jobsys-explore 4.0.1 → 4.0.2
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/.changeset/blue-bees-fix.md +5 -0
- package/CHANGELOG.md +7 -0
- package/components/form/ExAddress.jsx +46 -10
- package/components/form/ExField.jsx +2 -1
- package/components/form/ExForm.jsx +1 -0
- package/components/provider/ExProvider.jsx +39 -0
- package/dist/jobsys-explore.cjs +6 -6
- package/dist/jobsys-explore.cjs.map +1 -1
- package/dist/jobsys-explore.js +927 -861
- package/dist/jobsys-explore.js.map +1 -1
- package/package.json +1 -1
- package/playground/App.vue +12 -1
- package/playground/TestForm.vue +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { computed, defineComponent, ref, watch } from "vue"
|
|
1
|
+
import { computed, defineComponent, inject, ref, watch } from "vue"
|
|
2
2
|
import { Cascader } from "vant"
|
|
3
3
|
import localData from "./addressData.json"
|
|
4
4
|
import PickerWrapper, { pickerProps, pickerSlots } from "./PickerWrapper.jsx"
|
|
5
5
|
import { defaultFieldProps, defaultOptionsProps, useOptionTrait } from "../utils"
|
|
6
|
-
import { isArray, last } from "lodash-es"
|
|
6
|
+
import { cloneDeep, isArray, last } from "lodash-es"
|
|
7
7
|
import { useFindTextsFromPath } from "../../hooks"
|
|
8
|
+
import { EX_ADDRESS } from "../provider/ExProvider.jsx"
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* 地址组件
|
|
@@ -31,9 +32,23 @@ export default defineComponent({
|
|
|
31
32
|
* 1: 省, 2: 省市, 3: 省市区
|
|
32
33
|
*/
|
|
33
34
|
level: { type: Number, default: 3 },
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 显示值的类型
|
|
38
|
+
* 空值或all: 所有, last:最后
|
|
39
|
+
*/
|
|
40
|
+
displayTextType: { type: String, default: "" },
|
|
34
41
|
},
|
|
35
42
|
emits: ["update:modelValue"],
|
|
36
43
|
setup(props, { emit, slots, expose }) {
|
|
44
|
+
const addressProvider = inject(EX_ADDRESS, () => ({}))
|
|
45
|
+
const defaultAddressUrl = addressProvider.addressUrl || ""
|
|
46
|
+
const defaultDisplayTextType = addressProvider.displayTextType || ""
|
|
47
|
+
const defaultAfterFetched = addressProvider.afterFetched || ""
|
|
48
|
+
const optionKeys = addressProvider.optionKeys || {}
|
|
49
|
+
|
|
50
|
+
const { text: textKey, value: valueKey, children: childrenKey } = optionKeys
|
|
51
|
+
|
|
37
52
|
const defaultValue = isArray(props.modelValue) ? last(props.modelValue) : props.modelValue
|
|
38
53
|
|
|
39
54
|
const componentValue = ref(defaultValue)
|
|
@@ -50,20 +65,41 @@ export default defineComponent({
|
|
|
50
65
|
if (props.modelValue.length === 0) {
|
|
51
66
|
return ""
|
|
52
67
|
}
|
|
53
|
-
|
|
54
|
-
value:
|
|
55
|
-
children:
|
|
56
|
-
label:
|
|
57
|
-
})
|
|
68
|
+
const optionsTexts = useFindTextsFromPath(options.value, props.modelValue, {
|
|
69
|
+
value: valueKey,
|
|
70
|
+
children: childrenKey,
|
|
71
|
+
label: textKey,
|
|
72
|
+
})
|
|
73
|
+
const displayTextType = props.displayTextType || defaultDisplayTextType
|
|
74
|
+
return displayTextType === "last" ? optionsTexts[optionsTexts.length - 1] : optionsTexts.join("/")
|
|
58
75
|
})
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
//把默认值赋值给props
|
|
78
|
+
const cloneProps = cloneDeep(props)
|
|
79
|
+
if (!cloneProps.url && defaultAddressUrl) {
|
|
80
|
+
cloneProps.url = defaultAddressUrl
|
|
81
|
+
}
|
|
82
|
+
if (!cloneProps.afterFetched && defaultAfterFetched) {
|
|
83
|
+
cloneProps.afterFetched = defaultAfterFetched
|
|
84
|
+
}
|
|
85
|
+
//先处理好 options
|
|
86
|
+
const dealOptions = () => {
|
|
87
|
+
useOptionTrait(options, cloneProps, localData)
|
|
88
|
+
}
|
|
89
|
+
dealOptions()
|
|
90
|
+
|
|
91
|
+
watch(
|
|
92
|
+
() => props.options,
|
|
93
|
+
() => {
|
|
94
|
+
dealOptions()
|
|
95
|
+
},
|
|
96
|
+
)
|
|
61
97
|
|
|
62
98
|
const onFinish = ({ selectedOptions }) => {
|
|
63
99
|
pickerRef.value.close()
|
|
64
100
|
emit(
|
|
65
101
|
"update:modelValue",
|
|
66
|
-
selectedOptions.map((item) => item
|
|
102
|
+
selectedOptions.map((item) => item[valueKey]),
|
|
67
103
|
)
|
|
68
104
|
}
|
|
69
105
|
|
|
@@ -78,7 +114,7 @@ export default defineComponent({
|
|
|
78
114
|
default: () => (
|
|
79
115
|
<Cascader
|
|
80
116
|
v-model={componentValue.value}
|
|
81
|
-
fieldNames={{ text:
|
|
117
|
+
fieldNames={{ text: textKey, value: valueKey, children: childrenKey }}
|
|
82
118
|
closeable={false}
|
|
83
119
|
showHeader={false}
|
|
84
120
|
options={options.value}
|
|
@@ -87,7 +87,8 @@ export default defineComponent({
|
|
|
87
87
|
|
|
88
88
|
const appendElem = () => {
|
|
89
89
|
if (props.append) {
|
|
90
|
-
|
|
90
|
+
const appendResult = isString(props.append) ? props.append : props.append()
|
|
91
|
+
return appendResult ? <div class={"ex-field__append"}>{appendResult}</div> : null
|
|
91
92
|
}
|
|
92
93
|
return null
|
|
93
94
|
}
|
|
@@ -112,6 +112,7 @@ export default defineComponent({
|
|
|
112
112
|
* @property {array|Function} [options] 组件选项
|
|
113
113
|
* @property {string} [placeholder] 组件里的提示
|
|
114
114
|
* @property {string|Function} [help] ExField 里的提示
|
|
115
|
+
* @property {string|Function} [append] ExField 外的提示
|
|
115
116
|
* @property {array} [rules] 验证规则
|
|
116
117
|
* @property {boolean} [is-link] 是否展示右侧箭头并开启点击反馈
|
|
117
118
|
* @property {boolean} [readonly] 是否只读
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineComponent, provide } from "vue"
|
|
2
2
|
|
|
3
3
|
export const EX_UPLOADER = Symbol("EX_UPLOADER")
|
|
4
|
+
export const EX_ADDRESS = Symbol("EX_ADDRESS")
|
|
4
5
|
export const EX_FORM = Symbol("EX_FORM")
|
|
5
6
|
export const EX_SEARCH = Symbol("EX_SEARCH")
|
|
6
7
|
export const EX_PAGINATION = Symbol("EX_PAGINATION")
|
|
@@ -14,6 +15,7 @@ export default defineComponent({
|
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {Object} ProviderProps
|
|
16
17
|
* @property {UploaderProviderProps} [uploader] `ExUploader` 配置
|
|
18
|
+
* @property {AddressProviderProps} [address] `ExAddress` 配置
|
|
17
19
|
* @property {FormProviderProps} [form] `ExForm` 配置
|
|
18
20
|
* @property {SearchProviderProps} [search] `ExSearch` 配置
|
|
19
21
|
* @property {PaginationProviderProps} [pagination] `ExPagination` 配置
|
|
@@ -46,6 +48,32 @@ export default defineComponent({
|
|
|
46
48
|
}),
|
|
47
49
|
},
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {Object} AddressProviderProps `ExAddress` 配置
|
|
53
|
+
* @property {string} addressUrl 选项请求地址
|
|
54
|
+
* @property {string} displayTextType 显示值的类型
|
|
55
|
+
* @property {Function} [afterFetched] 处理接口返回数据的函数
|
|
56
|
+
* @property {AddressOptionKeys} optionKeys 地址选项键名
|
|
57
|
+
*
|
|
58
|
+
* @typedef {Object} AddressOptionKeys 地址选项键名
|
|
59
|
+
* @property {string} optionKeys.value 选项对应的值
|
|
60
|
+
* @property {string} optionKeys.text 选项文字
|
|
61
|
+
* @property {string} optionKeys.children 子选项列表
|
|
62
|
+
*/
|
|
63
|
+
address: {
|
|
64
|
+
type: Object,
|
|
65
|
+
default: () => ({
|
|
66
|
+
addressUrl: "",
|
|
67
|
+
displayTextType: "",
|
|
68
|
+
afterFetched: null,
|
|
69
|
+
optionKeys: {
|
|
70
|
+
value: "code",
|
|
71
|
+
text: "name",
|
|
72
|
+
children: "children",
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
},
|
|
76
|
+
|
|
49
77
|
/**
|
|
50
78
|
* @typedef {Object} FormProviderProps `ExForm` 配置
|
|
51
79
|
* @property {Object} [format] 格式化配置, 如 {date: true} 表示在提交表单时使用 `useFormFormat` 格式所有日期字段
|
|
@@ -114,6 +142,17 @@ export default defineComponent({
|
|
|
114
142
|
...props.uploader?.defaultFileItem,
|
|
115
143
|
},
|
|
116
144
|
})
|
|
145
|
+
provide(EX_ADDRESS, {
|
|
146
|
+
addressUrl: props.address?.addressUrl || "",
|
|
147
|
+
displayTextType: props.address?.displayTextType || "",
|
|
148
|
+
afterFetched: props.address?.afterFetched,
|
|
149
|
+
optionKeys: {
|
|
150
|
+
value: "code",
|
|
151
|
+
text: "name",
|
|
152
|
+
children: "children",
|
|
153
|
+
...props.address?.optionKeys,
|
|
154
|
+
},
|
|
155
|
+
})
|
|
117
156
|
provide(EX_FORM, { format: {}, ...props.form })
|
|
118
157
|
provide(EX_SEARCH, {
|
|
119
158
|
maskClass: "",
|