@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.
- 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/MAxios.vue +141 -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/MPassword.vue +73 -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 +55 -0
- package/src/components/grid/MBlock.vue +39 -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 +302 -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 +123 -0
- package/src/types/components.d.ts +769 -27
- package/src/types/dt.d.ts +144 -0
- package/src/types/index.d.ts +155 -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 +293 -0
- package/src/utils/Str.ts +211 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/myth.ts +95 -0
- package/src/utils/vee-rules.ts +32 -0
- package/src/utils/vue-plugin.ts +129 -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
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export * from './src/types'
|
|
10
|
+
|
|
11
|
+
export * from './src/components'
|
|
12
|
+
export * from './src/composable'
|
|
13
|
+
export * from './src/utils'
|
|
14
|
+
export { ThemeBtn } from './src/types/theme'
|
|
15
|
+
export { ThemeInput } from './src/types/theme'
|
|
16
|
+
export { ThemeShadow } from './src/types/theme'
|
|
17
|
+
export { ThemeSize } from './src/types/theme'
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mythpe/quasar-ui-qui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26-dev",
|
|
4
4
|
"description": "MyTh Quasar UI Kit App Extension",
|
|
5
|
-
"author":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "MyTh Ahmed Faiz",
|
|
7
|
+
"mobile": "+966590470092",
|
|
8
|
+
"email": "mythpe@gmail.com",
|
|
9
|
+
"url": "https://www.4myth.com"
|
|
10
|
+
},
|
|
8
11
|
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
9
13
|
"module": "src/index.esm.js",
|
|
10
14
|
"main": "src/index.common.js",
|
|
11
|
-
"type": "module",
|
|
12
15
|
"scripts": {
|
|
13
16
|
"dev": "cd ../dev && yarn dev && cd ..",
|
|
14
17
|
"dev:umd": "yarn build && node build/script.open-umd.js",
|
|
@@ -21,14 +24,15 @@
|
|
|
21
24
|
"build:css": "node build/script.css.js"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"typed.js": "^2.1.0",
|
|
25
|
-
"vee-validate": "^4.14.0",
|
|
26
27
|
"@vee-validate/i18n": "^4.14.0",
|
|
27
28
|
"@vee-validate/rules": "^4.14.0",
|
|
29
|
+
"axios": "^1.7.8",
|
|
30
|
+
"lodash": "^4.17.0",
|
|
31
|
+
"typed.js": "^2.1.0",
|
|
32
|
+
"vee-validate": "^4.14.0",
|
|
28
33
|
"vue-i18n": "^10.0.0"
|
|
29
34
|
},
|
|
30
35
|
"devDependencies": {
|
|
31
|
-
"lodash": "^4.17.21",
|
|
32
36
|
"@quasar/app-webpack": "^3.13.0",
|
|
33
37
|
"@quasar/extras": "^1.16.4",
|
|
34
38
|
"@rollup/plugin-buble": "^0.21.3",
|
|
@@ -60,8 +64,10 @@
|
|
|
60
64
|
"sass": "^1.33.0",
|
|
61
65
|
"typescript": "~5.5.3",
|
|
62
66
|
"uglify-js": "^3.13.3",
|
|
67
|
+
"vite-plugin-checker": "^0.8.0",
|
|
63
68
|
"vue": "^3.0.0",
|
|
64
69
|
"vue-router": "^4.0.0",
|
|
70
|
+
"vue-tsc": "^2.0.29",
|
|
65
71
|
"zlib": "^1.0.5"
|
|
66
72
|
},
|
|
67
73
|
"browserslist": [
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { boot } from 'quasar/wrappers'
|
|
10
|
+
import Plugin from '../utils/vue-plugin'
|
|
11
|
+
|
|
12
|
+
export default boot(({ app }) => {
|
|
13
|
+
app.use(Plugin)
|
|
14
|
+
})
|
|
@@ -0,0 +1,324 @@
|
|
|
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
|
+
<script lang="ts" setup>
|
|
10
|
+
import { computed, nextTick, onBeforeUnmount, ref, useTemplateRef, watch } from 'vue'
|
|
11
|
+
|
|
12
|
+
import MFile from './MFile.vue'
|
|
13
|
+
import type { MAvatarViewerProps as Props } from '../../types'
|
|
14
|
+
import { useField, useFieldError } from 'vee-validate'
|
|
15
|
+
import { useBindInput, useMyth } from '../../composable'
|
|
16
|
+
|
|
17
|
+
interface P {
|
|
18
|
+
auto?: Props['auto'];
|
|
19
|
+
col?: Props['col'];
|
|
20
|
+
xs?: Props['xs'];
|
|
21
|
+
sm?: Props['sm'];
|
|
22
|
+
md?: Props['md'];
|
|
23
|
+
lg?: Props['lg'];
|
|
24
|
+
xl?: Props['xl'];
|
|
25
|
+
accept?: Props['accept'];
|
|
26
|
+
images?: Props['images'];
|
|
27
|
+
svg?: Props['svg'];
|
|
28
|
+
video?: Props['video'];
|
|
29
|
+
pdf?: Props['pdf'];
|
|
30
|
+
excel?: Props['excel'];
|
|
31
|
+
size?: Props['size'];
|
|
32
|
+
avatarText?: Props['avatarText'];
|
|
33
|
+
fit?: Props['fit'];
|
|
34
|
+
clearable?: Props['clearable'];
|
|
35
|
+
label?: Props['label'];
|
|
36
|
+
rounded?: Props['rounded'];
|
|
37
|
+
name?: Props['name'];
|
|
38
|
+
caption?: Props['caption'];
|
|
39
|
+
captionProps?: Props['captionProps'];
|
|
40
|
+
hint?: Props['hint'];
|
|
41
|
+
hintProps?: Props['hintProps'];
|
|
42
|
+
formErrors?: Props['formErrors'];
|
|
43
|
+
help?: Props['help'];
|
|
44
|
+
readonly?: Props['readonly'];
|
|
45
|
+
loading?: Props['loading'];
|
|
46
|
+
required?: Props['required'];
|
|
47
|
+
rules?: Props['rules'];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const props = withDefaults(defineProps<P>(), {
|
|
51
|
+
auto: undefined,
|
|
52
|
+
col: undefined,
|
|
53
|
+
xs: undefined,
|
|
54
|
+
sm: undefined,
|
|
55
|
+
md: undefined,
|
|
56
|
+
lg: undefined,
|
|
57
|
+
xl: undefined,
|
|
58
|
+
accept: undefined,
|
|
59
|
+
images: !0,
|
|
60
|
+
svg: !0,
|
|
61
|
+
video: !1,
|
|
62
|
+
pdf: !1,
|
|
63
|
+
excel: !1,
|
|
64
|
+
size: () => '100px',
|
|
65
|
+
avatarText: undefined,
|
|
66
|
+
fit: () => 'contain',
|
|
67
|
+
clearable: undefined,
|
|
68
|
+
label: undefined,
|
|
69
|
+
rounded: undefined,
|
|
70
|
+
name: 'avatar',
|
|
71
|
+
hint: undefined,
|
|
72
|
+
hintProps: undefined,
|
|
73
|
+
caption: undefined,
|
|
74
|
+
captionProps: undefined,
|
|
75
|
+
formErrors: () => ({}),
|
|
76
|
+
help: undefined,
|
|
77
|
+
readonly: () => !1,
|
|
78
|
+
loading: () => !1,
|
|
79
|
+
required: undefined,
|
|
80
|
+
rules: () => ({})
|
|
81
|
+
})
|
|
82
|
+
type Emits = {
|
|
83
|
+
(e: 'click', evt?: Event): void;
|
|
84
|
+
}
|
|
85
|
+
const emit = defineEmits<Emits>()
|
|
86
|
+
const { __ } = useMyth()
|
|
87
|
+
const { accepts } = useBindInput<any>(() => props, 'avatarViewer')
|
|
88
|
+
const modelValueScope = useField<Props['modelValue']>(() => props.name, undefined, {
|
|
89
|
+
syncVModel: !0
|
|
90
|
+
})
|
|
91
|
+
const { value: modelValue, handleReset } = modelValueScope
|
|
92
|
+
const errorMessage = useFieldError(() => props.name)
|
|
93
|
+
const removedScope = useField<Props['removed']>(() => `${props.name}_removed`, undefined, {
|
|
94
|
+
syncVModel: 'removed'
|
|
95
|
+
})
|
|
96
|
+
const { handleChange: handleRemoved } = removedScope
|
|
97
|
+
|
|
98
|
+
const urlScope = useField<Props['url']>(() => `${props.name}_url`, undefined, {
|
|
99
|
+
syncVModel: 'url'
|
|
100
|
+
})
|
|
101
|
+
const { value: url, handleChange: handleUrl } = urlScope
|
|
102
|
+
|
|
103
|
+
const fileRef = useTemplateRef<typeof MFile>('fileRef')
|
|
104
|
+
const pickFiles = () => fileRef.value?.pickFiles()
|
|
105
|
+
const removeFile = () => fileRef.value?.removeAtIndex(0)
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Blob file to url helpers
|
|
109
|
+
*/
|
|
110
|
+
const blobUrl = ref<string | null>(null)
|
|
111
|
+
const isLoaded = ref(!1)
|
|
112
|
+
const revoke = () => {
|
|
113
|
+
if (blobUrl.value) {
|
|
114
|
+
URL.revokeObjectURL(blobUrl.value)
|
|
115
|
+
blobUrl.value = null
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const toUrl = (data?: any) => {
|
|
119
|
+
revoke()
|
|
120
|
+
blobUrl.value = URL.createObjectURL(data)
|
|
121
|
+
return blobUrl
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const hasSrc = computed(() => !!modelValue.value || !!url.value)
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if blob value is a File & not image
|
|
128
|
+
*/
|
|
129
|
+
const isFile = computed(() => {
|
|
130
|
+
if (!(modelValue.value instanceof File)) {
|
|
131
|
+
return !1
|
|
132
|
+
}
|
|
133
|
+
return modelValue.value instanceof File && modelValue.value?.type.slice(0, 6) !== 'image/'
|
|
134
|
+
})
|
|
135
|
+
const getAvatarText = computed(() => props.avatarText ? props.avatarText.slice(0, 1).toUpperCase() : undefined)
|
|
136
|
+
const loadingSrc = ref(!1)
|
|
137
|
+
const onClick = (e?: Event) => {
|
|
138
|
+
if (props.readonly) {
|
|
139
|
+
if (loadingSrc.value) {
|
|
140
|
+
loadingSrc.value = !1
|
|
141
|
+
}
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
loadingSrc.value = !0
|
|
145
|
+
nextTick(() => {
|
|
146
|
+
if (props.clearable && hasSrc.value && !props.required) {
|
|
147
|
+
onClearInput()
|
|
148
|
+
handleReset()
|
|
149
|
+
loadingSrc.value = !1
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
handleReset()
|
|
153
|
+
pickFiles()
|
|
154
|
+
nextTick(() => {
|
|
155
|
+
emit('click', e)
|
|
156
|
+
loadingSrc.value = !1
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
const onClearInput = () => {
|
|
161
|
+
removeFile()
|
|
162
|
+
handleRemoved(!0, !1)
|
|
163
|
+
handleUrl(null, !1)
|
|
164
|
+
}
|
|
165
|
+
onBeforeUnmount(() => {
|
|
166
|
+
revoke()
|
|
167
|
+
removeFile()
|
|
168
|
+
handleRemoved(undefined, !1)
|
|
169
|
+
})
|
|
170
|
+
watch(modelValue, (v) => {
|
|
171
|
+
if (props.readonly) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
if (v instanceof File) {
|
|
175
|
+
nextTick(() => toUrl(v))
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
defineOptions({
|
|
180
|
+
name: 'MAvatarViewer',
|
|
181
|
+
inheritAttrs: !1
|
|
182
|
+
})
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<MCol
|
|
187
|
+
:auto="auto"
|
|
188
|
+
:class="$attrs.class"
|
|
189
|
+
:col="col"
|
|
190
|
+
:lg="lg"
|
|
191
|
+
:md="md"
|
|
192
|
+
:name="name"
|
|
193
|
+
:sm="sm"
|
|
194
|
+
:xs="xs"
|
|
195
|
+
>
|
|
196
|
+
<MColumn class="items-center">
|
|
197
|
+
<MTransition>
|
|
198
|
+
<div
|
|
199
|
+
v-if="!!label"
|
|
200
|
+
key="label"
|
|
201
|
+
class="row items-center"
|
|
202
|
+
>
|
|
203
|
+
<q-skeleton
|
|
204
|
+
v-if="loading"
|
|
205
|
+
class="q-mb-md"
|
|
206
|
+
height="22px"
|
|
207
|
+
width="80px"
|
|
208
|
+
/>
|
|
209
|
+
<div
|
|
210
|
+
v-else
|
|
211
|
+
:class="`text-h6 q-px-sm rounded-borders q-mb-sm ${!!errorMessage ? 'text-negative' : ''}`"
|
|
212
|
+
>
|
|
213
|
+
{{ __(label) }}
|
|
214
|
+
<span
|
|
215
|
+
v-if="!clearable"
|
|
216
|
+
class="text-negative"
|
|
217
|
+
>*</span>
|
|
218
|
+
</div>
|
|
219
|
+
<MHelpRow
|
|
220
|
+
v-if="!!help && !loading"
|
|
221
|
+
:text="help"
|
|
222
|
+
tooltip
|
|
223
|
+
/>
|
|
224
|
+
</div>
|
|
225
|
+
<slot name="hint">
|
|
226
|
+
<div
|
|
227
|
+
v-if="!!hint && !loading"
|
|
228
|
+
key="hint"
|
|
229
|
+
class="m--input__hint"
|
|
230
|
+
v-bind="hintProps"
|
|
231
|
+
>
|
|
232
|
+
<span>{{ __(hint) }}</span>
|
|
233
|
+
</div>
|
|
234
|
+
</slot>
|
|
235
|
+
<div
|
|
236
|
+
key="avatar"
|
|
237
|
+
:class="`rounded-borders q-mb-sm ${!!errorMessage ? 'q-pa-xs bg-negative' : ''}`"
|
|
238
|
+
>
|
|
239
|
+
<q-skeleton
|
|
240
|
+
v-if="loading"
|
|
241
|
+
:size="size"
|
|
242
|
+
type="QAvatar"
|
|
243
|
+
/>
|
|
244
|
+
<q-avatar
|
|
245
|
+
v-else
|
|
246
|
+
:color="!!errorMessage ? 'negative' : ((!isLoaded || !hasSrc || isFile) ? 'primary' : undefined)"
|
|
247
|
+
:icon="isFile ? 'o_description' : undefined"
|
|
248
|
+
:rounded="rounded === undefined ? hasSrc : rounded"
|
|
249
|
+
:size="size"
|
|
250
|
+
text-color="white"
|
|
251
|
+
>
|
|
252
|
+
<q-img
|
|
253
|
+
v-if="hasSrc && !isFile"
|
|
254
|
+
:fit="fit"
|
|
255
|
+
:height="size"
|
|
256
|
+
:src="blobUrl || url"
|
|
257
|
+
ratio="1"
|
|
258
|
+
@error="isLoaded = !0"
|
|
259
|
+
@load="isLoaded = !0"
|
|
260
|
+
>
|
|
261
|
+
<template #loading>
|
|
262
|
+
<div class="text-white">
|
|
263
|
+
<q-spinner-ios />
|
|
264
|
+
</div>
|
|
265
|
+
</template>
|
|
266
|
+
</q-img>
|
|
267
|
+
<div
|
|
268
|
+
v-if="getAvatarText && !hasSrc"
|
|
269
|
+
class="text-white text-h3"
|
|
270
|
+
v-text="getAvatarText"
|
|
271
|
+
/>
|
|
272
|
+
</q-avatar>
|
|
273
|
+
</div>
|
|
274
|
+
<div
|
|
275
|
+
v-if="!readonly"
|
|
276
|
+
key="btn"
|
|
277
|
+
class="q-mb-sm"
|
|
278
|
+
>
|
|
279
|
+
<q-skeleton
|
|
280
|
+
v-if="loading"
|
|
281
|
+
type="QBtn"
|
|
282
|
+
/>
|
|
283
|
+
<MBtn
|
|
284
|
+
v-else
|
|
285
|
+
:color="!hasSrc ? 'positive' : 'secondary'"
|
|
286
|
+
:disable="!isLoaded && !!url"
|
|
287
|
+
:icon="hasSrc ? 'ion-ios-close' : 'ion-ios-attach'"
|
|
288
|
+
:label="__( clearable && hasSrc ? 'remove' : ( !clearable && hasSrc ? 'change' : 'choose') )"
|
|
289
|
+
:loading="loadingSrc"
|
|
290
|
+
@click="onClick"
|
|
291
|
+
/>
|
|
292
|
+
</div>
|
|
293
|
+
<div
|
|
294
|
+
v-if="!!errorMessage"
|
|
295
|
+
key="errors"
|
|
296
|
+
class="q-mb-sm"
|
|
297
|
+
>
|
|
298
|
+
<span class="text-body2 text-negative">{{ errorMessage }}</span>
|
|
299
|
+
</div>
|
|
300
|
+
</MTransition>
|
|
301
|
+
<slot name="caption">
|
|
302
|
+
<div
|
|
303
|
+
v-if="!!caption"
|
|
304
|
+
class="m--input__caption"
|
|
305
|
+
v-bind="captionProps"
|
|
306
|
+
>
|
|
307
|
+
{{ __(caption) }}
|
|
308
|
+
</div>
|
|
309
|
+
</slot>
|
|
310
|
+
</MColumn>
|
|
311
|
+
<slot />
|
|
312
|
+
<MFile
|
|
313
|
+
key="file"
|
|
314
|
+
ref="fileRef"
|
|
315
|
+
v-model="modelValue"
|
|
316
|
+
:accept="accepts.join(',')"
|
|
317
|
+
:clearable="clearable"
|
|
318
|
+
:name="name || ''"
|
|
319
|
+
:required="required"
|
|
320
|
+
:rules="rules"
|
|
321
|
+
class="hidden"
|
|
322
|
+
/>
|
|
323
|
+
</MCol>
|
|
324
|
+
</template>
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
<script lang="ts" setup>
|
|
10
|
+
|
|
11
|
+
import type { MAxiosProps as Props, MSelectModelEmit } from '../../types'
|
|
12
|
+
import type { QSelectSlots } from 'quasar'
|
|
13
|
+
import { computed, onMounted, ref, toValue, watch } from 'vue'
|
|
14
|
+
import { useSetFieldValue } from 'vee-validate'
|
|
15
|
+
import MSelect from './MSelect.vue'
|
|
16
|
+
import { useMyth } from '../../composable'
|
|
17
|
+
|
|
18
|
+
type P = {
|
|
19
|
+
name: Props['name'];
|
|
20
|
+
label?: Props['label'];
|
|
21
|
+
placeholder?: Props['placeholder'];
|
|
22
|
+
viewMode?: Props['viewMode'];
|
|
23
|
+
viewModeValue?: Props['viewModeValue'];
|
|
24
|
+
service?: Props['service'];
|
|
25
|
+
guest?: Props['guest'];
|
|
26
|
+
requestWith?: Props['requestWith'];
|
|
27
|
+
params?: Props['params'];
|
|
28
|
+
lazy?: Props['lazy'];
|
|
29
|
+
useChoice?: Props['useChoice'];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const props = withDefaults(defineProps<P>(), {
|
|
33
|
+
name: () => '',
|
|
34
|
+
label: undefined,
|
|
35
|
+
placeholder: undefined,
|
|
36
|
+
viewMode: () => !1,
|
|
37
|
+
viewModeValue: undefined,
|
|
38
|
+
service: undefined,
|
|
39
|
+
guest: undefined,
|
|
40
|
+
requestWith: undefined,
|
|
41
|
+
params: () => () => ({}),
|
|
42
|
+
lazy: () => !1,
|
|
43
|
+
useChoice: undefined
|
|
44
|
+
})
|
|
45
|
+
const modelValue = defineModel<Props['modelValue']>({ required: !1, default: undefined })
|
|
46
|
+
type Emits = {
|
|
47
|
+
(e: 'model', value: MSelectModelEmit): void;
|
|
48
|
+
}
|
|
49
|
+
const emit = defineEmits<Emits>()
|
|
50
|
+
const search = defineModel<string>('search', { required: !1, default: '' })
|
|
51
|
+
const setFieldValue = useSetFieldValue(() => props.name)
|
|
52
|
+
const { alertError, api } = useMyth()
|
|
53
|
+
const loading = defineModel<Props['loading']>('loading', { required: !1, default: !1 })
|
|
54
|
+
const items = defineModel<Props['items']>('items', { required: !1, default: [] })
|
|
55
|
+
const isGuest = computed(() => {
|
|
56
|
+
const v = toValue(props.guest)
|
|
57
|
+
return v !== undefined && v !== null && v !== !1
|
|
58
|
+
})
|
|
59
|
+
const prepare = async (fromWatch = !1) => {
|
|
60
|
+
if (!props.service || loading.value) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
const method = typeof props.service === 'string'
|
|
64
|
+
? (isGuest.value ? api.value[props.service].staticIndex : api.value[props.service].index)
|
|
65
|
+
: props.service
|
|
66
|
+
if (!method) {
|
|
67
|
+
throw Error(`No service: ${props.service}`)
|
|
68
|
+
}
|
|
69
|
+
const params: any = {
|
|
70
|
+
requestWith: undefined,
|
|
71
|
+
search: search.value,
|
|
72
|
+
itemsPerPage: -1,
|
|
73
|
+
page: 1,
|
|
74
|
+
staticRequest: 1,
|
|
75
|
+
...(toValue(props.params) || {})
|
|
76
|
+
}
|
|
77
|
+
if (props.requestWith) {
|
|
78
|
+
params.requestWith = toValue(props.requestWith)
|
|
79
|
+
}
|
|
80
|
+
loading.value = !0
|
|
81
|
+
items.value = []
|
|
82
|
+
method({ params })
|
|
83
|
+
.then(({ _data }: any) => {
|
|
84
|
+
items.value = _data || []
|
|
85
|
+
})
|
|
86
|
+
.catch((e: any) => {
|
|
87
|
+
alertError(e?.message || 'An error occurred')
|
|
88
|
+
})
|
|
89
|
+
.finally(() => {
|
|
90
|
+
loading.value = !1
|
|
91
|
+
if (fromWatch) {
|
|
92
|
+
if (modelValue.value !== null && modelValue.value !== undefined) {
|
|
93
|
+
setFieldValue(undefined)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
const listeners = {
|
|
99
|
+
'update:search': prepare,
|
|
100
|
+
model: (v: MSelectModelEmit) => emit('model', v)
|
|
101
|
+
}
|
|
102
|
+
onMounted(() => {
|
|
103
|
+
if (!props.lazy) {
|
|
104
|
+
prepare()
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
watch(props.params, () => prepare(!0), { deep: !0 })
|
|
108
|
+
const input = ref<InstanceType<typeof MSelect> | null>(null)
|
|
109
|
+
defineExpose<{ input: typeof input }>({ input })
|
|
110
|
+
defineOptions({ name: 'MAxios', inheritAttrs: !1 })
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<template>
|
|
114
|
+
<MSelect
|
|
115
|
+
ref="input"
|
|
116
|
+
v-model="modelValue"
|
|
117
|
+
v-model:loading="loading"
|
|
118
|
+
v-model:search="search"
|
|
119
|
+
:label="label"
|
|
120
|
+
:name="name"
|
|
121
|
+
:options="items"
|
|
122
|
+
:placeholder="placeholder"
|
|
123
|
+
:view-mode="viewMode"
|
|
124
|
+
:view-mode-value="viewModeValue"
|
|
125
|
+
axios-mode
|
|
126
|
+
no-filter
|
|
127
|
+
v-bind="$attrs"
|
|
128
|
+
v-on="listeners"
|
|
129
|
+
>
|
|
130
|
+
<template
|
|
131
|
+
v-for="(_,slot) in $slots as Readonly<QSelectSlots>"
|
|
132
|
+
:key="slot"
|
|
133
|
+
#[slot]="inputSlot"
|
|
134
|
+
>
|
|
135
|
+
<slot
|
|
136
|
+
:name="slot"
|
|
137
|
+
v-bind="inputSlot || {}"
|
|
138
|
+
/>
|
|
139
|
+
</template>
|
|
140
|
+
</MSelect>
|
|
141
|
+
</template>
|