@mythpe/quasar-ui-qui 0.0.24 → 0.0.25-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.
- package/index.d.ts +17 -0
- package/package.json +14 -8
- package/src/boot/register.ts +14 -0
- package/src/components/form/MAvatarViewer.vue +324 -0
- package/src/components/form/MBtn.vue +271 -93
- package/src/components/form/MCheckbox.vue +126 -0
- package/src/components/form/MColor.vue +122 -0
- package/src/components/form/MDate.vue +47 -0
- package/src/components/form/MEditor.vue +285 -0
- package/src/components/form/MEmail.vue +40 -0
- package/src/components/form/MField.vue +145 -0
- package/src/components/form/MFile.vue +212 -0
- package/src/components/form/MForm.vue +86 -0
- package/src/components/form/MHidden.vue +86 -0
- package/src/components/form/MHiddenInput.vue +55 -0
- package/src/components/form/MInput.vue +178 -0
- package/src/components/form/MInputFieldControl.vue +27 -0
- package/src/components/form/MInputLabel.vue +35 -0
- package/src/components/form/MMobile.vue +40 -0
- package/src/components/form/MPicker.vue +313 -0
- package/src/components/form/MRadio.vue +178 -0
- package/src/components/form/MSelect.vue +349 -0
- package/src/components/form/MTime.vue +45 -0
- package/src/components/form/index.ts +51 -0
- package/src/components/grid/MBlock.vue +40 -18
- package/src/components/grid/MCol.vue +11 -15
- package/src/components/grid/MColumn.vue +8 -0
- package/src/components/grid/MContainer.vue +22 -13
- package/src/components/grid/MHelpRow.vue +9 -12
- package/src/components/grid/MRow.vue +31 -10
- package/src/components/grid/index.ts +16 -0
- package/src/components/index.ts +12 -0
- package/src/components/transition/MFadeTransition.vue +27 -0
- package/src/components/transition/MFadeXTransition.vue +26 -0
- package/src/components/transition/MTransition.vue +41 -0
- package/src/components/transition/index.ts +13 -0
- package/src/components/typography/MTypingString.vue +8 -0
- package/src/components/typography/index.ts +11 -0
- package/src/composable/index.ts +12 -0
- package/src/composable/useBindInput.ts +209 -0
- package/src/composable/useError.ts +11 -0
- package/src/composable/useMyth.ts +294 -0
- package/src/composable/useValue.ts +12 -0
- package/src/index.common.js +19 -1
- package/src/index.esm.js +18 -3
- package/src/index.js +19 -0
- package/src/index.sass +8 -26
- package/src/index.ts +18 -4
- package/src/index.umd.js +17 -2
- package/src/style/m-container.sass +13 -0
- package/src/style/main.sass +42 -0
- package/src/types/api-helpers.d.ts +120 -0
- package/src/types/components.d.ts +688 -28
- package/src/types/dt.d.ts +144 -0
- package/src/types/index.d.ts +153 -1
- package/src/types/lodash.d.ts +26 -0
- package/src/types/quasar-helpers.d.ts +7 -0
- package/src/types/theme.d.ts +12 -0
- package/src/utils/Helpers.ts +314 -0
- package/src/utils/Str.ts +211 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/myth.ts +90 -0
- package/src/utils/vee-rules.ts +32 -0
- package/src/utils/vue-plugin.ts +122 -0
- package/tsconfig.json +9 -13
- package/src/myth.ts +0 -30
- package/src/types/myth.ts +0 -42
- package/src/vue-plugin.ts +0 -41
- 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'])[]
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,2 +1,154 @@
|
|
|
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
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default loading q-btn loading slot.
|
|
35
|
+
*/
|
|
36
|
+
export type BtnLoading = {
|
|
37
|
+
type: 'audio' | 'ball' | 'bars' | 'box' | 'clock' | 'comment' | 'cube' | 'dots' | 'facebook' | 'gears' | 'grid' | 'hearts' | 'hourglass' | 'infinity' | 'ios' | 'orbit' | 'oval' | 'pie' | 'puff' | 'radio' | 'rings' | 'tail' | 'spinner';
|
|
38
|
+
color?: string | undefined;
|
|
39
|
+
size?: string | undefined;
|
|
40
|
+
noLabel?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PropsContext {
|
|
44
|
+
// Grid.
|
|
45
|
+
/**
|
|
46
|
+
* MBlock component.
|
|
47
|
+
*/
|
|
48
|
+
block?: Partial<MBlockProps>;
|
|
49
|
+
/**
|
|
50
|
+
* MCol component.
|
|
51
|
+
*/
|
|
52
|
+
col?: Partial<MColProps>;
|
|
53
|
+
/**
|
|
54
|
+
* MColumn component.
|
|
55
|
+
*/
|
|
56
|
+
column?: Partial<MColumnProps>;
|
|
57
|
+
/**
|
|
58
|
+
* MContainer component.
|
|
59
|
+
*/
|
|
60
|
+
container?: Partial<MContainerProps>;
|
|
61
|
+
/**
|
|
62
|
+
* MHelpRow component.
|
|
63
|
+
*/
|
|
64
|
+
helpRow?: Partial<MHelpRowProps>;
|
|
65
|
+
/**
|
|
66
|
+
* MRow component.
|
|
67
|
+
*/
|
|
68
|
+
row?: Partial<MRowProps>;
|
|
69
|
+
/**
|
|
70
|
+
* MTypingString component.
|
|
71
|
+
*/
|
|
72
|
+
typingString?: Partial<MTypingStringProps>;
|
|
73
|
+
/**
|
|
74
|
+
* MAvatarViewer component.
|
|
75
|
+
*/
|
|
76
|
+
avatarViewer?: Partial<MAvatarViewerProps>;
|
|
77
|
+
/**
|
|
78
|
+
* MBtn component.
|
|
79
|
+
*/
|
|
80
|
+
btn?: Partial<MBtnProps>;
|
|
81
|
+
/**
|
|
82
|
+
* MInput component.
|
|
83
|
+
*/
|
|
84
|
+
input?: Partial<MInputProps>;
|
|
85
|
+
/**
|
|
86
|
+
* MFile component.
|
|
87
|
+
*/
|
|
88
|
+
file?: Partial<MFileProps>;
|
|
89
|
+
/**
|
|
90
|
+
* MMobile component.
|
|
91
|
+
*/
|
|
92
|
+
mobile?: Partial<MInputProps>;
|
|
93
|
+
/**
|
|
94
|
+
* MInput view mode props.
|
|
95
|
+
*/
|
|
96
|
+
field?: Partial<QFieldProps>;
|
|
97
|
+
/**
|
|
98
|
+
* MCheckbox component.
|
|
99
|
+
*/
|
|
100
|
+
checkbox?: Partial<MCheckboxProps>;
|
|
101
|
+
/**
|
|
102
|
+
* MRadio component.
|
|
103
|
+
*/
|
|
104
|
+
radio?: Partial<MRadioProps>;
|
|
105
|
+
/**
|
|
106
|
+
* MSelect component.
|
|
107
|
+
*/
|
|
108
|
+
select?: Partial<MSelectProps>;
|
|
109
|
+
/**
|
|
110
|
+
* MPicker component.
|
|
111
|
+
*/
|
|
112
|
+
picker?: Partial<MPickerProps>;
|
|
113
|
+
/**
|
|
114
|
+
* q-btn component props.
|
|
115
|
+
*/
|
|
116
|
+
pickerBtn?: Partial<QBtnProps>;
|
|
117
|
+
/**
|
|
118
|
+
* MDate component.
|
|
119
|
+
*/
|
|
120
|
+
date?: Partial<MDateProps>;
|
|
121
|
+
/**
|
|
122
|
+
* MEditor component.
|
|
123
|
+
*/
|
|
124
|
+
editor?: Partial<MEditorProps>;
|
|
125
|
+
/**
|
|
126
|
+
* MTime component.
|
|
127
|
+
*/
|
|
128
|
+
time?: Partial<MTimeProps>;
|
|
129
|
+
/**
|
|
130
|
+
* Notify Props.
|
|
131
|
+
*/
|
|
132
|
+
notify?: Partial<QNotifyCreateOptions>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface InstallOptions {
|
|
136
|
+
size?: ThemeSize;
|
|
137
|
+
rounded?: ThemeRounded;
|
|
138
|
+
shadow?: ThemeShadow;
|
|
139
|
+
fluid?: ThemeFluid;
|
|
140
|
+
rules?: string[];
|
|
141
|
+
btnLoading?: BtnLoading;
|
|
142
|
+
props?: PropsContext;
|
|
143
|
+
themeInput?: ThemeInput;
|
|
144
|
+
themeBtn?: ThemeBtn;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type MythContext = typeof myth;
|
|
148
|
+
|
|
149
|
+
export * from './api-helpers'
|
|
1
150
|
export * from './components'
|
|
2
|
-
export * from './
|
|
151
|
+
export * from './dt'
|
|
152
|
+
export * from './lodash'
|
|
153
|
+
export * from './quasar-helpers'
|
|
154
|
+
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,314 @@
|
|
|
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 { AxiosInstance, AxiosRequestConfig } from 'axios'
|
|
10
|
+
import lodash from 'lodash'
|
|
11
|
+
import { openURL, scroll } from 'quasar'
|
|
12
|
+
import type { ConfigType, DownloadFromResponse, DownloadFromResponseCode, HelpersStubSchema, ParamsType, UrlType } from '../types'
|
|
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
|
+
// return typeof config === 'boolean' ? u : axios().get(u, config)
|
|
62
|
+
},
|
|
63
|
+
async staticIndex (config?: ConfigType) {
|
|
64
|
+
const u = `Static${baseUrl ? `/${baseUrl}` : ''}`
|
|
65
|
+
return axios().get(u, config)
|
|
66
|
+
// config = config || {}
|
|
67
|
+
// config.params = {
|
|
68
|
+
// page: 1,
|
|
69
|
+
// itemsPerPage: -1,
|
|
70
|
+
// ...(config.params ?? {})
|
|
71
|
+
// }
|
|
72
|
+
// return axios().get(u, config)
|
|
73
|
+
},
|
|
74
|
+
async export (data?: ParamsType, config?: AxiosRequestConfig) {
|
|
75
|
+
return axios().post(makeUrl('Export'), data, config)
|
|
76
|
+
},
|
|
77
|
+
async store (data?: ParamsType, config?: AxiosRequestConfig) {
|
|
78
|
+
const u = makeUrl()
|
|
79
|
+
// if (typeof data === 'boolean') {
|
|
80
|
+
// return u
|
|
81
|
+
// }
|
|
82
|
+
const formData = new FormData()
|
|
83
|
+
data && Helpers.appendArray(formData, data)
|
|
84
|
+
return axios().post(u, formData, config)
|
|
85
|
+
},
|
|
86
|
+
async show (id: UrlType, config?: AxiosRequestConfig) {
|
|
87
|
+
const u = makeUrl(id)
|
|
88
|
+
return axios().get(u, config)
|
|
89
|
+
// return typeof id === 'boolean' ? u : axios().get(u, config)
|
|
90
|
+
},
|
|
91
|
+
async staticShow (id: UrlType, config?: AxiosRequestConfig) {
|
|
92
|
+
// const m = baseUrl ? baseUrl.toString().split('/').pop() : ''
|
|
93
|
+
// const u = 'Static' + (m ? `/${m}` : '') + `/${id}`
|
|
94
|
+
const u = `Static${baseUrl ? `/${baseUrl}` : ''}` + `/${id}`
|
|
95
|
+
// if (typeof id === 'boolean') {
|
|
96
|
+
// return u
|
|
97
|
+
// }
|
|
98
|
+
return axios().get(u, config)
|
|
99
|
+
},
|
|
100
|
+
async update (id: UrlType, data?: ParamsType, config?: AxiosRequestConfig) {
|
|
101
|
+
const u = makeUrl(id)
|
|
102
|
+
// if (typeof id === 'boolean') {
|
|
103
|
+
// return u
|
|
104
|
+
// }
|
|
105
|
+
const formData = new FormData()
|
|
106
|
+
formData.append('_method', 'put')
|
|
107
|
+
data && Helpers.appendArray(formData, data)
|
|
108
|
+
return axios().post(u, formData, config)
|
|
109
|
+
},
|
|
110
|
+
async destroy (id: UrlType, config?: AxiosRequestConfig) {
|
|
111
|
+
const u = makeUrl(id)
|
|
112
|
+
return axios().delete(u, config)
|
|
113
|
+
// return typeof id === 'boolean' ? u : axios().delete(u, config)
|
|
114
|
+
},
|
|
115
|
+
async destroyAll (ids?: UrlType[], config?: AxiosRequestConfig) {
|
|
116
|
+
const u = makeUrl('DestroyAll')
|
|
117
|
+
return axios().post(u, { ids: (ids || []) }, config)
|
|
118
|
+
},
|
|
119
|
+
getUploadAttachmentsUrl: (id: UrlType) => makeUrl(`${id}/Attachment/Upload`),
|
|
120
|
+
async uploadAttachments (id: UrlType, data: Record<string, any>, config?: AxiosRequestConfig) {
|
|
121
|
+
const _url = makeUrl(`${id}/Attachment/Upload`)
|
|
122
|
+
return axios().post(_url, data, config)
|
|
123
|
+
},
|
|
124
|
+
async deleteAttachment (id: UrlType, fileId: string | number, config?: AxiosRequestConfig) {
|
|
125
|
+
const _url = makeUrl(`${id}/Attachment/${fileId}/Delete`)
|
|
126
|
+
return axios().delete(_url, config)
|
|
127
|
+
},
|
|
128
|
+
async updateAttachment (id: UrlType, fileId: string | number, data: Record<string, any>, config?: AxiosRequestConfig) {
|
|
129
|
+
const _url = makeUrl(`${id}/Attachment/${fileId}/Update`)
|
|
130
|
+
return axios().post(_url, data, config)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
StubUrl: (group?: UrlType): ((segments?: UrlType, parent?: UrlType) => string) => (
|
|
135
|
+
segments?: UrlType,
|
|
136
|
+
parent?: UrlType
|
|
137
|
+
): string => ((parent ?? '') + (parent && group ? '/' : '')) + (group ?? '') + ((group && segments ? '/' : '') + (segments ?? '')),
|
|
138
|
+
findBy (search: any, value: any, column: string | number = 'id') {
|
|
139
|
+
return lodash.find(search, (e: any) => lodash.isPlainObject(e) ? e[column] === value : e === value)
|
|
140
|
+
},
|
|
141
|
+
// queryStringify: (v: never) => new URLSearchParams(qs.stringify(v, {
|
|
142
|
+
// arrayFormat: 'indices'
|
|
143
|
+
// // encodeValuesOnly: true,
|
|
144
|
+
// // encode: false,
|
|
145
|
+
// })),
|
|
146
|
+
/**
|
|
147
|
+
* Open unique window popup of application
|
|
148
|
+
*
|
|
149
|
+
* @param url
|
|
150
|
+
* @param reject
|
|
151
|
+
* @param windowFeatures
|
|
152
|
+
*/
|
|
153
|
+
openWindow<F extends (...args: any[]) => any> (url: string, reject?: F, windowFeatures?: object) {
|
|
154
|
+
return openURL(url, reject, windowFeatures)
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* Customized helper to download blob from axios response
|
|
158
|
+
* @param response
|
|
159
|
+
* @param callback
|
|
160
|
+
*/
|
|
161
|
+
downloadFromResponse (response: any, callback?: ((url: string, response: any) => void)) {
|
|
162
|
+
return new Promise<DownloadFromResponse>((resolve, reject) => {
|
|
163
|
+
const rejectPromise = (e?: { code: DownloadFromResponseCode }) => reject(e ?? { status: !1, code: 'unknown' })
|
|
164
|
+
const resolvePromise = (response: DownloadFromResponse['response']) => resolve({ status: !0, response })
|
|
165
|
+
try {
|
|
166
|
+
if (!response) {
|
|
167
|
+
rejectPromise({ code: 'no_response' })
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (response?.data?.data?.url) {
|
|
172
|
+
const url = response?.data?.data?.url
|
|
173
|
+
if (callback) {
|
|
174
|
+
callback(url, response)
|
|
175
|
+
resolvePromise(response)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
const elm = document.createElement('a')
|
|
179
|
+
elm.setAttribute('href', url)
|
|
180
|
+
elm.setAttribute('target', '_blank')
|
|
181
|
+
document.body.appendChild(elm)
|
|
182
|
+
elm.click()
|
|
183
|
+
resolvePromise(response)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const name = (response.headers['content-disposition'] || '').split('filename=').pop().replace(/^"+|"+$/g, '')
|
|
188
|
+
if (!name) {
|
|
189
|
+
rejectPromise({ code: 'no_file_name' })
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
const file = new Blob([response.data])
|
|
193
|
+
const fileURL = window.URL.createObjectURL(file)
|
|
194
|
+
const fileLink = document.createElement('a')
|
|
195
|
+
if (!fileLink || !fileURL) {
|
|
196
|
+
rejectPromise({ code: 'no_file_url' })
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fileLink.href = fileURL
|
|
201
|
+
fileLink.setAttribute('download', name)
|
|
202
|
+
document.body.appendChild(fileLink)
|
|
203
|
+
fileLink.click()
|
|
204
|
+
resolvePromise(response)
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
try {
|
|
207
|
+
document.body.removeChild(fileLink)
|
|
208
|
+
URL.revokeObjectURL(fileURL)
|
|
209
|
+
} catch (e: any) {
|
|
210
|
+
console.log(e)
|
|
211
|
+
if (e?.message) {
|
|
212
|
+
alert(e.message)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}, 3000)
|
|
216
|
+
} catch (e: any) {
|
|
217
|
+
console.log(e)
|
|
218
|
+
rejectPromise(e)
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
async scrollToElement (el: HTMLElement | string, opt?: { target?: HTMLElement | string, duration?: number; }) {
|
|
223
|
+
await nextTick()
|
|
224
|
+
const { getScrollTarget, setVerticalScrollPosition, getVerticalScrollPosition } = scroll
|
|
225
|
+
const scrollTo = typeof el === 'string' ? document.querySelector(el) as HTMLElement : el
|
|
226
|
+
if (!scrollTo) {
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
await nextTick()
|
|
230
|
+
const { target: t } = opt || {}
|
|
231
|
+
const targetSelector = typeof t === 'string' ? document.querySelector(t) as HTMLElement : t
|
|
232
|
+
const target = getScrollTarget(scrollTo, targetSelector || window.document.documentElement)
|
|
233
|
+
// console.log(targetSelector, target)
|
|
234
|
+
// let offset = 0
|
|
235
|
+
// try {
|
|
236
|
+
// let parent = scrollTo
|
|
237
|
+
// do {
|
|
238
|
+
// // console.log(parent.getBoundingClientRect().top)
|
|
239
|
+
// offset += parent?.offsetTop || 0
|
|
240
|
+
// parent = parent.offsetParent as HTMLElement
|
|
241
|
+
// } while (parent?.offsetParent)
|
|
242
|
+
// } catch (e) {
|
|
243
|
+
// offset = scrollTo?.offsetTop || 0
|
|
244
|
+
// }
|
|
245
|
+
// offset = scrollTo.getBoundingClientRect().top
|
|
246
|
+
const current = getVerticalScrollPosition(target)
|
|
247
|
+
// console.log(current, target)
|
|
248
|
+
// const offset = scrollTo.getBoundingClientRect().top
|
|
249
|
+
const duration = opt?.duration || 1000
|
|
250
|
+
|
|
251
|
+
let offset = 0
|
|
252
|
+
let parent = scrollTo
|
|
253
|
+
try {
|
|
254
|
+
do {
|
|
255
|
+
offset = parent.getBoundingClientRect().top
|
|
256
|
+
if (offset === 0 && !parent.parentElement) {
|
|
257
|
+
offset = parent.scrollTop
|
|
258
|
+
break
|
|
259
|
+
} else if (offset !== 0 && parent.parentElement) {
|
|
260
|
+
break
|
|
261
|
+
}
|
|
262
|
+
parent = parent.parentElement as HTMLElement
|
|
263
|
+
} while (parent)
|
|
264
|
+
} catch (e) {
|
|
265
|
+
console.log(e)
|
|
266
|
+
offset = scrollTo?.offsetTop || 0
|
|
267
|
+
}
|
|
268
|
+
// console.log(offset, parent, current)
|
|
269
|
+
// const position = offset
|
|
270
|
+
// if (offset > current) {
|
|
271
|
+
// position = (current - offset) + current
|
|
272
|
+
// } else if (offset < current) {
|
|
273
|
+
// position = current + offset
|
|
274
|
+
// }
|
|
275
|
+
// console.log({
|
|
276
|
+
// target,
|
|
277
|
+
// scrollTo,
|
|
278
|
+
// position,
|
|
279
|
+
// offset,
|
|
280
|
+
// current
|
|
281
|
+
// })
|
|
282
|
+
setVerticalScrollPosition(target, (offset + current) - 100, duration)
|
|
283
|
+
},
|
|
284
|
+
async scrollToElementFromErrors (errors?: Partial<Record<string, string[] | string | null | undefined>>, elm?: any, target?: any) {
|
|
285
|
+
if (!errors) {
|
|
286
|
+
return
|
|
287
|
+
}
|
|
288
|
+
for (const [name, value] of Object.entries(errors)) {
|
|
289
|
+
const val = value && Array.isArray(value) ? value[0] : value
|
|
290
|
+
if (val?.toString?.()?.length) {
|
|
291
|
+
if (!elm) {
|
|
292
|
+
const selector = `[data-input-name='${name}']`
|
|
293
|
+
const e = document.querySelector(selector) as HTMLElement
|
|
294
|
+
// console.log(e)
|
|
295
|
+
await this.scrollToElement(e || `[name='${name}']`, { target })
|
|
296
|
+
} else {
|
|
297
|
+
await this.scrollToElement(elm, { target })
|
|
298
|
+
}
|
|
299
|
+
break
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
makeUrl (path: string) {
|
|
304
|
+
path = path || ''
|
|
305
|
+
if (path.slice(0, 1) === '/') {
|
|
306
|
+
path = path.slice(1)
|
|
307
|
+
}
|
|
308
|
+
if (window) {
|
|
309
|
+
const l = window.location
|
|
310
|
+
return `${l.protocol}//${l.host}/${path}`
|
|
311
|
+
}
|
|
312
|
+
return `//${path}`
|
|
313
|
+
}
|
|
314
|
+
}
|