@mythpe/quasar-ui-qui 0.0.25 → 0.0.26-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/index.d.ts +17 -0
  2. package/package.json +14 -8
  3. package/src/boot/register.ts +14 -0
  4. package/src/components/form/MAvatarViewer.vue +324 -0
  5. package/src/components/form/MAxios.vue +141 -0
  6. package/src/components/form/MBtn.vue +271 -93
  7. package/src/components/form/MCheckbox.vue +126 -0
  8. package/src/components/form/MColor.vue +122 -0
  9. package/src/components/form/MDate.vue +47 -0
  10. package/src/components/form/MEditor.vue +285 -0
  11. package/src/components/form/MEmail.vue +40 -0
  12. package/src/components/form/MField.vue +145 -0
  13. package/src/components/form/MFile.vue +212 -0
  14. package/src/components/form/MForm.vue +86 -0
  15. package/src/components/form/MHidden.vue +86 -0
  16. package/src/components/form/MHiddenInput.vue +55 -0
  17. package/src/components/form/MInput.vue +178 -0
  18. package/src/components/form/MInputFieldControl.vue +27 -0
  19. package/src/components/form/MInputLabel.vue +35 -0
  20. package/src/components/form/MMobile.vue +40 -0
  21. package/src/components/form/MPassword.vue +73 -0
  22. package/src/components/form/MPicker.vue +313 -0
  23. package/src/components/form/MRadio.vue +178 -0
  24. package/src/components/form/MSelect.vue +349 -0
  25. package/src/components/form/MTime.vue +45 -0
  26. package/src/components/form/index.ts +55 -0
  27. package/src/components/grid/MBlock.vue +39 -18
  28. package/src/components/grid/MCol.vue +11 -15
  29. package/src/components/grid/MColumn.vue +8 -0
  30. package/src/components/grid/MContainer.vue +22 -13
  31. package/src/components/grid/MHelpRow.vue +9 -12
  32. package/src/components/grid/MRow.vue +31 -10
  33. package/src/components/grid/index.ts +16 -0
  34. package/src/components/index.ts +12 -0
  35. package/src/components/transition/MFadeTransition.vue +27 -0
  36. package/src/components/transition/MFadeXTransition.vue +26 -0
  37. package/src/components/transition/MTransition.vue +41 -0
  38. package/src/components/transition/index.ts +13 -0
  39. package/src/components/typography/MTypingString.vue +8 -0
  40. package/src/components/typography/index.ts +11 -0
  41. package/src/composable/index.ts +12 -0
  42. package/src/composable/useBindInput.ts +209 -0
  43. package/src/composable/useError.ts +11 -0
  44. package/src/composable/useMyth.ts +302 -0
  45. package/src/composable/useValue.ts +12 -0
  46. package/src/index.common.js +19 -1
  47. package/src/index.esm.js +18 -3
  48. package/src/index.js +19 -0
  49. package/src/index.sass +8 -26
  50. package/src/index.ts +18 -4
  51. package/src/index.umd.js +17 -2
  52. package/src/style/m-container.sass +13 -0
  53. package/src/style/main.sass +42 -0
  54. package/src/types/api-helpers.d.ts +123 -0
  55. package/src/types/components.d.ts +769 -27
  56. package/src/types/dt.d.ts +144 -0
  57. package/src/types/index.d.ts +155 -1
  58. package/src/types/lodash.d.ts +26 -0
  59. package/src/types/quasar-helpers.d.ts +7 -0
  60. package/src/types/theme.d.ts +12 -0
  61. package/src/utils/Helpers.ts +293 -0
  62. package/src/utils/Str.ts +211 -0
  63. package/src/utils/index.ts +13 -0
  64. package/src/utils/myth.ts +95 -0
  65. package/src/utils/vee-rules.ts +32 -0
  66. package/src/utils/vue-plugin.ts +129 -0
  67. package/tsconfig.json +9 -13
  68. package/src/myth.ts +0 -30
  69. package/src/types/myth.ts +0 -42
  70. package/src/vue-plugin.ts +0 -41
  71. package/types.d.ts +0 -1
@@ -0,0 +1,144 @@
1
+ import type { QTableProps } from 'quasar'
2
+ import type { GenericFormValues, MDatatableProps, MDtBtnProps } from './components'
3
+ import type { MaybeRef, Ref, UnwrapRef } from 'vue'
4
+ import type { AxiosResponse } from 'axios'
5
+
6
+ type Generic = Record<any, any>;
7
+
8
+ export type MDtItem<T extends object = Record<keyof T, any>> = T & {
9
+ id: string | number;
10
+ [K: keyof T]: any;
11
+ }
12
+ export type MDtItemIndex = number;
13
+ export type MDtExportOptions = 'pdf' | 'excel';
14
+
15
+ type MDDIP<T extends Generic = Generic | any> = Partial<MDtItem> & Record<string, any> | T;
16
+ export type MDatatableDialogsOptions<T extends MDDIP = MDDIP> = {
17
+ filter: Ref<boolean>;
18
+ show: Ref<boolean>;
19
+ form: Ref<boolean>;
20
+ isUpdate: Ref<boolean>;
21
+ item: T | MaybeRef<MDDIP<T>> | UnwrapRef<MDDIP<T>> | Record<string, any> | undefined;
22
+ index: Ref<MDtItemIndex | undefined>;
23
+ errors: Record<string | number | symbol, string[]> | any;
24
+ }
25
+
26
+ type E = MDatatableDialogsOptions['item'];
27
+ export type GenericMDtBtn<T extends E = E> = Record<string, any> & {
28
+ name: string;
29
+ label?: string;
30
+ contextLabel?: string | null;
31
+ tooltip?: string;
32
+ click?: (item: UnwrapRef<T> | Ref<T> | T, index: UnwrapRef<MDatatableDialogsOptions['index']>) => void;
33
+ multiClick?: (items: T[]) => void;
34
+ showIf?: boolean | ((item: UnwrapRef<MDatatableDialogsOptions['item']>, index: UnwrapRef<MDatatableDialogsOptions['index']>) => boolean);
35
+ order?: number;
36
+ attr?: Partial<MDtBtnProps> & Partial<{ icon?: string; textColor?: string; color?: string; }>;
37
+ }
38
+
39
+ export interface ApiServiceParams {
40
+ filter?: Record<string, any>;
41
+ search?: string | null;
42
+ searchColumns?: string[] | string;
43
+ // headers: string[];
44
+ headerItems?: any[] | string[] | string;
45
+ ids?: number[];
46
+ indexType: 'index' | 'pdf' | 'excel';
47
+ // For Datatable, index,export-pdf|excel,update,create,show,delete
48
+ fdt: 'i' | 'e' | 'u' | 'c' | 's' | 'd';
49
+ requestWith?: string;
50
+ itemsPerPage: number;
51
+ page: number;
52
+ sortBy?: string;
53
+ sortDesc?: number;
54
+ toUrl?: MDtExportOptions | boolean;
55
+
56
+ [key: string]: any;
57
+ }
58
+
59
+ export type MDtServiceNameCallbackProp = (() => Record<string, (() => Promise<AxiosResponse>)>)
60
+ export type MDtServiceNameStringProp = string
61
+ export type MDtRequestParamsCallbackProp = (params: ApiServiceParams) => Partial<GenericFormValues>
62
+ export type MDtRequestParamsObjectProp = Partial<GenericFormValues>
63
+
64
+ export type ParseHeaderOptions = {
65
+ controlKey?: 'control' | string
66
+ controlStyle?: 'max-width: 150px' | string
67
+ align?: 'left' | 'right' | 'center' | undefined
68
+ sortable?: boolean | undefined;
69
+ classes?: string | (() => string),
70
+ noSort?: string[]
71
+ }
72
+
73
+ // export interface ParsedHeader {
74
+ // /**
75
+ // * Unique id, identifies column, (used by pagination.sortBy, 'body-cell-[name]' slot, ...)
76
+ // */
77
+ // name: string;
78
+ // /**
79
+ // * Label for header
80
+ // */
81
+ // label: string;
82
+ // /**
83
+ // * Row Object property to determine value for this column or function which maps to the required property
84
+ // * @param row The current row being processed
85
+ // * @returns Value for this column
86
+ // */
87
+ // field: string | ((row: any) => any);
88
+ // /**
89
+ // * If we use visible-columns, this col will always be visible
90
+ // */
91
+ // required?: boolean;
92
+ // /**
93
+ // * Horizontal alignment of cells in this column
94
+ // * Default value: right
95
+ // */
96
+ // align?: 'left' | 'right' | 'center';
97
+ // /**
98
+ // * Tell QTable you want this column sortable
99
+ // */
100
+ // sortable?: boolean;
101
+ // /**
102
+ // * Compare function if you have some custom data or want a specific way to compare two rows
103
+ // * @param a Value of the first comparison term
104
+ // * @param b Value of the second comparison term
105
+ // * @param rowA Full Row object in which is contained the first term
106
+ // * @param rowB Full Row object in which is contained the second term
107
+ // * @returns Comparison result of term 'a' with term 'b'. Less than 0 when 'a' should come first; greater than 0 if 'b' should come first; equal to 0 if their position must not be changed with respect to each other
108
+ // */
109
+ // sort?: (a: any, b: any, rowA: any, rowB: any) => number;
110
+ // /**
111
+ // * Set column sort order: 'ad' (ascending-descending) or 'da' (descending-ascending); Overrides the 'column-sort-order' prop
112
+ // * Default value: ad
113
+ // */
114
+ // sortOrder?: 'ad' | 'da';
115
+ // /**
116
+ // * Function you can apply to format your data
117
+ // * @param val Value of the cell
118
+ // * @param row Full Row object in which the cell is contained
119
+ // * @returns The resulting formatted value
120
+ // */
121
+ // format?: (val: any, row: any) => any;
122
+ // /**
123
+ // * Style to apply on normal cells of the column
124
+ // * @param row The current row being processed
125
+ // */
126
+ // style?: string | ((row: any) => string);
127
+ // /**
128
+ // * Classes to add on normal cells of the column
129
+ // * @param row The current row being processed
130
+ // */
131
+ // classes?: string | ((row: any) => string);
132
+ // /**
133
+ // * Style to apply on header cells of the column
134
+ // */
135
+ // headerStyle?: string;
136
+ // /**
137
+ // * Classes to add on header cells of the column
138
+ // */
139
+ // headerClasses?: string;
140
+ // }
141
+
142
+ export type MDtColumn = QTableProps['columns'][number]
143
+
144
+ export type MDtHeadersParameter = MDtColumn[] | (keyof MDatatableProps['defaultItem'])[]
@@ -1,2 +1,156 @@
1
+ /*
2
+ * MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
3
+ * Email: mythpe@gmail.com
4
+ * Mobile: +966590470092
5
+ * Website: https://www.4myth.com
6
+ * Github: https://github.com/mythpe
7
+ */
8
+
9
+ import type { QBtnProps, QFieldProps, QNotifyCreateOptions } from 'quasar'
10
+ import {
11
+ MAvatarViewerProps,
12
+ MBlockProps,
13
+ MBtnProps,
14
+ MCheckboxProps,
15
+ MColProps,
16
+ MColumnProps,
17
+ MContainerProps,
18
+ MDateProps,
19
+ MEditorProps,
20
+ MFileProps,
21
+ MHelpRowProps,
22
+ MInputProps,
23
+ MPickerProps,
24
+ MRadioProps,
25
+ MRowProps,
26
+ MSelectProps,
27
+ MTimeProps,
28
+ MTypingStringProps
29
+ } from './components'
30
+ import { myth } from '../utils'
31
+ import { ThemeBtn, ThemeFluid, ThemeInput, ThemeRounded, ThemeShadow, ThemeSize } from './theme'
32
+ import { HelpersStubSchema } from './api-helpers'
33
+
34
+ /**
35
+ * Default loading q-btn loading slot.
36
+ */
37
+ export type BtnLoading = {
38
+ type: 'audio' | 'ball' | 'bars' | 'box' | 'clock' | 'comment' | 'cube' | 'dots' | 'facebook' | 'gears' | 'grid' | 'hearts' | 'hourglass' | 'infinity' | 'ios' | 'orbit' | 'oval' | 'pie' | 'puff' | 'radio' | 'rings' | 'tail' | 'spinner';
39
+ color?: string | undefined;
40
+ size?: string | undefined;
41
+ noLabel?: boolean;
42
+ }
43
+
44
+ export interface PropsContext {
45
+ // Grid.
46
+ /**
47
+ * MBlock component.
48
+ */
49
+ block?: Partial<MBlockProps>;
50
+ /**
51
+ * MCol component.
52
+ */
53
+ col?: Partial<MColProps>;
54
+ /**
55
+ * MColumn component.
56
+ */
57
+ column?: Partial<MColumnProps>;
58
+ /**
59
+ * MContainer component.
60
+ */
61
+ container?: Partial<MContainerProps>;
62
+ /**
63
+ * MHelpRow component.
64
+ */
65
+ helpRow?: Partial<MHelpRowProps>;
66
+ /**
67
+ * MRow component.
68
+ */
69
+ row?: Partial<MRowProps>;
70
+ /**
71
+ * MTypingString component.
72
+ */
73
+ typingString?: Partial<MTypingStringProps>;
74
+ /**
75
+ * MAvatarViewer component.
76
+ */
77
+ avatarViewer?: Partial<MAvatarViewerProps>;
78
+ /**
79
+ * MBtn component.
80
+ */
81
+ btn?: Partial<MBtnProps>;
82
+ /**
83
+ * MInput component.
84
+ */
85
+ input?: Partial<MInputProps>;
86
+ /**
87
+ * MFile component.
88
+ */
89
+ file?: Partial<MFileProps>;
90
+ /**
91
+ * MMobile component.
92
+ */
93
+ mobile?: Partial<MInputProps>;
94
+ /**
95
+ * MInput view mode props.
96
+ */
97
+ field?: Partial<QFieldProps>;
98
+ /**
99
+ * MCheckbox component.
100
+ */
101
+ checkbox?: Partial<MCheckboxProps>;
102
+ /**
103
+ * MRadio component.
104
+ */
105
+ radio?: Partial<MRadioProps>;
106
+ /**
107
+ * MSelect component.
108
+ */
109
+ select?: Partial<MSelectProps>;
110
+ /**
111
+ * MPicker component.
112
+ */
113
+ picker?: Partial<MPickerProps>;
114
+ /**
115
+ * q-btn component props.
116
+ */
117
+ pickerBtn?: Partial<QBtnProps>;
118
+ /**
119
+ * MDate component.
120
+ */
121
+ date?: Partial<MDateProps>;
122
+ /**
123
+ * MEditor component.
124
+ */
125
+ editor?: Partial<MEditorProps>;
126
+ /**
127
+ * MTime component.
128
+ */
129
+ time?: Partial<MTimeProps>;
130
+ /**
131
+ * Notify Props.
132
+ */
133
+ notify?: Partial<QNotifyCreateOptions>;
134
+ }
135
+
136
+ export interface InstallOptions {
137
+ size?: ThemeSize;
138
+ rounded?: ThemeRounded;
139
+ shadow?: ThemeShadow;
140
+ fluid?: ThemeFluid;
141
+ rules?: string[];
142
+ btnLoading?: BtnLoading;
143
+ props?: PropsContext;
144
+ themeInput?: ThemeInput;
145
+ themeBtn?: ThemeBtn;
146
+ api?: HelpersStubSchema;
147
+ }
148
+
149
+ export type MythContext = typeof myth;
150
+
151
+ export * from './api-helpers'
1
152
  export * from './components'
2
- export * from './myth'
153
+ export * from './dt'
154
+ export * from './lodash'
155
+ export * from './quasar-helpers'
156
+ export * from './theme'
@@ -0,0 +1,26 @@
1
+ /*
2
+ * MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
3
+ * Email: mythpe@gmail.com
4
+ * Mobile: +966590470092
5
+ * Website: https://www.4myth.com
6
+ * Github: https://github.com/mythpe
7
+ */
8
+ /* eslint-disable */
9
+
10
+ declare module 'lodash' {
11
+ interface LoDashStatic {
12
+ /**
13
+ * Converts string to pascal case.
14
+ *
15
+ * @param string The string to convert.
16
+ * @return Returns the pascal cased string.
17
+ */
18
+ pascalCase (string?: string): string;
19
+
20
+ pluralize (string?: string): string;
21
+
22
+ singularize (string?: string): string;
23
+ }
24
+ }
25
+
26
+ export {}
@@ -0,0 +1,7 @@
1
+ import type { DialogChainObject, QNotifyCreateOptions, QNotifyUpdateOptions } from 'quasar'
2
+
3
+ export type Vue3MAlertMessageOptions = QNotifyCreateOptions | string;
4
+
5
+ export type Vue3MAlertMessage = (props?: QNotifyUpdateOptions) => void;
6
+
7
+ export type Vue3MConfirmMessage = DialogChainObject
@@ -0,0 +1,12 @@
1
+ import type { QBtnProps, QInputProps } from 'quasar'
2
+
3
+ export type ThemeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'none' | string;
4
+ export type ThemeShadow = string | number | 'transition' | 'none';
5
+ export type ThemeRounded = boolean;
6
+ export type ThemeFluid = boolean;
7
+ export type ThemeInput =
8
+ Partial<Pick<QInputProps, 'standout' | 'dense' | 'filled' | 'outlined' | 'rounded' | 'borderless' | 'counter' | 'noErrorIcon' | 'hideBottomSpace' | 'bottomSlots' | 'clearIcon' | 'itemAligned' | 'square' | 'stackLabel'>>
9
+ & {
10
+ topLabel?: boolean;
11
+ }
12
+ export type ThemeBtn = Partial<Pick<QBtnProps, 'flat' | 'outline' | 'push' | 'unelevated' | 'noCaps' | 'rounded' | 'glossy' | 'square' | 'padding' | 'ripple' | 'dense'>>
@@ -0,0 +1,293 @@
1
+ /*
2
+ * MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
3
+ * Email: mythpe@gmail.com
4
+ * Mobile: +966590470092
5
+ * Website: https://www.4myth.com
6
+ * Github: https://github.com/mythpe
7
+ */
8
+
9
+ import type { AxiosInstance, AxiosRequestConfig } from 'axios'
10
+ import type { ConfigType, DownloadFromResponse, DownloadFromResponseCode, HelpersStubSchema, ParamsType, UrlType } from '../types'
11
+ import lodash from 'lodash'
12
+ import { openURL, scroll } from 'quasar'
13
+
14
+ import { nextTick } from 'vue'
15
+
16
+ export const Helpers = {
17
+ appendArray (formData: FormData, values: File | Blob | Record<string, any> | any, name?: string | null | undefined) {
18
+ let value: never | any
19
+ if ((values instanceof File || values instanceof Blob) && name) {
20
+ const _name = values instanceof File ? values.name : name
21
+ formData.append(name, values, _name)
22
+ } else {
23
+ for (const key in values) {
24
+ value = values[key]
25
+ if (value !== null && value !== undefined && typeof value === 'object') {
26
+ const k = name ? name + '[' + key + ']' : key
27
+ if (lodash.isArray(value) && value.length < 1) {
28
+ formData.append(`${key}`, '')
29
+ } else {
30
+ this.appendArray(formData, value, k)
31
+ }
32
+ } else {
33
+ if (value === !0) {
34
+ value = 1
35
+ }
36
+ if (value === false) {
37
+ value = 0
38
+ }
39
+ if (value === null || value === undefined) {
40
+ value = ''
41
+ // console.log('null----', name,key, value)
42
+ }
43
+ // if (value !== undefined) {
44
+ if (name) {
45
+ formData.append(name + '[' + key + ']', value)
46
+ } else {
47
+ formData.append(key, value)
48
+ }
49
+ // }
50
+ }
51
+ }
52
+ }
53
+ return formData
54
+ },
55
+ Stub (baseUrl: UrlType, axios: () => AxiosInstance): HelpersStubSchema {
56
+ const makeUrl = Helpers.StubUrl(baseUrl)
57
+ return {
58
+ async index (config?: ConfigType) {
59
+ const u = makeUrl()
60
+ return axios().get(u, config)
61
+ },
62
+ async staticIndex (config?: ConfigType) {
63
+ const u = `Static${baseUrl ? `/${baseUrl}` : ''}`
64
+ return axios().get(u, config)
65
+ },
66
+ async export (data?: ParamsType, config?: AxiosRequestConfig) {
67
+ return axios().post(makeUrl('Export'), data, config)
68
+ },
69
+ async store (data?: ParamsType, config?: AxiosRequestConfig) {
70
+ const u = makeUrl()
71
+ const formData = new FormData()
72
+ data && Helpers.appendArray(formData, data)
73
+ return axios().post(u, formData, config)
74
+ },
75
+ async show (id: UrlType, config?: AxiosRequestConfig) {
76
+ const u = makeUrl(id)
77
+ return axios().get(u, config)
78
+ },
79
+ async staticShow (id: UrlType, config?: AxiosRequestConfig) {
80
+ const u = `Static${baseUrl ? `/${baseUrl}` : ''}` + `/${id}`
81
+ return axios().get(u, config)
82
+ },
83
+ async update (id: UrlType, data?: ParamsType, config?: AxiosRequestConfig) {
84
+ const u = makeUrl(id)
85
+ const formData = new FormData()
86
+ formData.append('_method', 'put')
87
+ data && Helpers.appendArray(formData, data)
88
+ return axios().post(u, formData, config)
89
+ },
90
+ async destroy (id: UrlType, config?: AxiosRequestConfig) {
91
+ const u = makeUrl(id)
92
+ return axios().delete(u, config)
93
+ },
94
+ async destroyAll (ids?: UrlType[], config?: AxiosRequestConfig) {
95
+ const u = makeUrl('DestroyAll')
96
+ return axios().post(u, { ids: (ids || []) }, config)
97
+ },
98
+ getUploadAttachmentsUrl: (id: UrlType): string => makeUrl(`${id}/Attachment/Upload`),
99
+ async uploadAttachments (id: UrlType, data: Record<string, any>, config?: AxiosRequestConfig) {
100
+ const _url = makeUrl(`${id}/Attachment/Upload`)
101
+ return axios().post(_url, data, config)
102
+ },
103
+ async deleteAttachment (id: UrlType, fileId: string | number, config?: AxiosRequestConfig) {
104
+ const _url = makeUrl(`${id}/Attachment/${fileId}/Delete`)
105
+ return axios().delete(_url, config)
106
+ },
107
+ async updateAttachment (id: UrlType, fileId: string | number, data: Record<string, any>, config?: AxiosRequestConfig) {
108
+ const _url = makeUrl(`${id}/Attachment/${fileId}/Update`)
109
+ return axios().post(_url, data, config)
110
+ }
111
+ }
112
+ },
113
+ StubUrl: (group?: UrlType): ((segments?: UrlType, parent?: UrlType) => string) => (
114
+ segments?: UrlType,
115
+ parent?: UrlType
116
+ ): string => ((parent ?? '') + (parent && group ? '/' : '')) + (group ?? '') + ((group && segments ? '/' : '') + (segments ?? '')),
117
+ findBy (search: any, value: any, column: string | number = 'id') {
118
+ return lodash.find(search, (e: any) => lodash.isPlainObject(e) ? e[column] === value : e === value)
119
+ },
120
+ // queryStringify: (v: never) => new URLSearchParams(qs.stringify(v, {
121
+ // arrayFormat: 'indices'
122
+ // // encodeValuesOnly: true,
123
+ // // encode: false,
124
+ // })),
125
+ /**
126
+ * Open unique window popup of application
127
+ *
128
+ * @param url
129
+ * @param reject
130
+ * @param windowFeatures
131
+ */
132
+ openWindow<F extends (...args: any[]) => any> (url: string, reject?: F, windowFeatures?: object) {
133
+ return openURL(url, reject, windowFeatures)
134
+ },
135
+ /**
136
+ * Customized helper to download blob from axios response
137
+ * @param response
138
+ * @param callback
139
+ */
140
+ downloadFromResponse (response: any, callback?: ((url: string, response: any) => void)) {
141
+ return new Promise<DownloadFromResponse>((resolve, reject) => {
142
+ const rejectPromise = (e?: { code: DownloadFromResponseCode }) => reject(e ?? { status: !1, code: 'unknown' })
143
+ const resolvePromise = (response: DownloadFromResponse['response']) => resolve({ status: !0, response })
144
+ try {
145
+ if (!response) {
146
+ rejectPromise({ code: 'no_response' })
147
+ return
148
+ }
149
+
150
+ if (response?.data?.data?.url) {
151
+ const url = response?.data?.data?.url
152
+ if (callback) {
153
+ callback(url, response)
154
+ resolvePromise(response)
155
+ return
156
+ }
157
+ const elm = document.createElement('a')
158
+ elm.setAttribute('href', url)
159
+ elm.setAttribute('target', '_blank')
160
+ document.body.appendChild(elm)
161
+ elm.click()
162
+ resolvePromise(response)
163
+ return
164
+ }
165
+
166
+ const name = (response.headers['content-disposition'] || '').split('filename=').pop().replace(/^"+|"+$/g, '')
167
+ if (!name) {
168
+ rejectPromise({ code: 'no_file_name' })
169
+ return
170
+ }
171
+ const file = new Blob([response.data])
172
+ const fileURL = window.URL.createObjectURL(file)
173
+ const fileLink = document.createElement('a')
174
+ if (!fileLink || !fileURL) {
175
+ rejectPromise({ code: 'no_file_url' })
176
+ return
177
+ }
178
+
179
+ fileLink.href = fileURL
180
+ fileLink.setAttribute('download', name)
181
+ document.body.appendChild(fileLink)
182
+ fileLink.click()
183
+ resolvePromise(response)
184
+ setTimeout(() => {
185
+ try {
186
+ document.body.removeChild(fileLink)
187
+ URL.revokeObjectURL(fileURL)
188
+ } catch (e: any) {
189
+ console.log(e)
190
+ if (e?.message) {
191
+ alert(e.message)
192
+ }
193
+ }
194
+ }, 3000)
195
+ } catch (e: any) {
196
+ console.log(e)
197
+ rejectPromise(e)
198
+ }
199
+ })
200
+ },
201
+ async scrollToElement (el: HTMLElement | string, opt?: { target?: HTMLElement | string, duration?: number; }) {
202
+ await nextTick()
203
+ const { getScrollTarget, setVerticalScrollPosition, getVerticalScrollPosition } = scroll
204
+ const scrollTo = typeof el === 'string' ? document.querySelector(el) as HTMLElement : el
205
+ if (!scrollTo) {
206
+ return
207
+ }
208
+ await nextTick()
209
+ const { target: t } = opt || {}
210
+ const targetSelector = typeof t === 'string' ? document.querySelector(t) as HTMLElement : t
211
+ const target = getScrollTarget(scrollTo, targetSelector || window.document.documentElement)
212
+ // console.log(targetSelector, target)
213
+ // let offset = 0
214
+ // try {
215
+ // let parent = scrollTo
216
+ // do {
217
+ // // console.log(parent.getBoundingClientRect().top)
218
+ // offset += parent?.offsetTop || 0
219
+ // parent = parent.offsetParent as HTMLElement
220
+ // } while (parent?.offsetParent)
221
+ // } catch (e) {
222
+ // offset = scrollTo?.offsetTop || 0
223
+ // }
224
+ // offset = scrollTo.getBoundingClientRect().top
225
+ const current = getVerticalScrollPosition(target)
226
+ // console.log(current, target)
227
+ // const offset = scrollTo.getBoundingClientRect().top
228
+ const duration = opt?.duration || 1000
229
+
230
+ let offset = 0
231
+ let parent = scrollTo
232
+ try {
233
+ do {
234
+ offset = parent.getBoundingClientRect().top
235
+ if (offset === 0 && !parent.parentElement) {
236
+ offset = parent.scrollTop
237
+ break
238
+ } else if (offset !== 0 && parent.parentElement) {
239
+ break
240
+ }
241
+ parent = parent.parentElement as HTMLElement
242
+ } while (parent)
243
+ } catch (e) {
244
+ console.log(e)
245
+ offset = scrollTo?.offsetTop || 0
246
+ }
247
+ // console.log(offset, parent, current)
248
+ // const position = offset
249
+ // if (offset > current) {
250
+ // position = (current - offset) + current
251
+ // } else if (offset < current) {
252
+ // position = current + offset
253
+ // }
254
+ // console.log({
255
+ // target,
256
+ // scrollTo,
257
+ // position,
258
+ // offset,
259
+ // current
260
+ // })
261
+ setVerticalScrollPosition(target, (offset + current) - 100, duration)
262
+ },
263
+ async scrollToElementFromErrors (errors?: Partial<Record<string, string[] | string | null | undefined>>, elm?: any, target?: any) {
264
+ if (!errors) {
265
+ return
266
+ }
267
+ for (const [name, value] of Object.entries(errors)) {
268
+ const val = value && Array.isArray(value) ? value[0] : value
269
+ if (val?.toString?.()?.length) {
270
+ if (!elm) {
271
+ const selector = `[data-input-name='${name}']`
272
+ const e = document.querySelector(selector) as HTMLElement
273
+ // console.log(e)
274
+ await this.scrollToElement(e || `[name='${name}']`, { target })
275
+ } else {
276
+ await this.scrollToElement(elm, { target })
277
+ }
278
+ break
279
+ }
280
+ }
281
+ },
282
+ makeUrl (path: string) {
283
+ path = path || ''
284
+ if (path.slice(0, 1) === '/') {
285
+ path = path.slice(1)
286
+ }
287
+ if (window) {
288
+ const l = window.location
289
+ return `${l.protocol}//${l.host}/${path}`
290
+ }
291
+ return `//${path}`
292
+ }
293
+ }