general-basic-form 2.0.52 → 2.0.53

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 (35) hide show
  1. package/README.assets/image-20210820173738506.png +0 -0
  2. package/README.md +1 -0
  3. package/package.json +3 -14
  4. package/script/link.ts +36 -0
  5. package/script/unlink.ts +45 -0
  6. package/src/Descriptions.vue +106 -0
  7. package/src/GeneralBasicForm.vue +277 -0
  8. package/src/InfiniteScrollList.vue +170 -0
  9. package/src/assets/image-20210820173037871.png +0 -0
  10. package/src/assets/logo.png +0 -0
  11. package/src/components/CustomCom/img-mask/index.vue +79 -0
  12. package/src/components/CustomCom/input-graphic-verification/index.vue +82 -0
  13. package/src/components/CustomCom/input-mobile-verification/index.vue +52 -0
  14. package/src/components/CustomCom/input-mobile-verification/verification-button.vue +81 -0
  15. package/src/components/VABasic/input/index.vue +75 -0
  16. package/src/components/VBasic/cascader/index.vue +32 -0
  17. package/src/components/VBasic/checkbox/index.vue +37 -0
  18. package/src/components/VBasic/date-picker/index.vue +31 -0
  19. package/src/components/VBasic/divider/index.vue +53 -0
  20. package/src/components/VBasic/input/index.vue +67 -0
  21. package/src/components/VBasic/input-number/index.vue +31 -0
  22. package/src/components/VBasic/radio/index.vue +37 -0
  23. package/src/components/VBasic/select/index.vue +37 -0
  24. package/src/components/setting.ts +28 -0
  25. package/src/index.ts +30 -0
  26. package/src/injectKey.ts +2 -0
  27. package/src/types/basicFrom.ts +63 -0
  28. package/src/types/componentType.ts +6 -0
  29. package/src/types/componentsProps.ts +18 -0
  30. package/tsconfig.json +14 -0
  31. package/vite.config.js +123 -0
  32. package/dist/index.js +0 -968
  33. package/dist/index.umd.cjs +0 -1
  34. package/dist/style.css +0 -1
  35. /package/{dist → public}/index.d.ts +0 -0
package/README.md CHANGED
@@ -540,6 +540,7 @@ formItem:[ {
540
540
  }
541
541
  }]
542
542
  componentType:"Ant Design Vue"|"Element Plus"(默认)
543
+ strict:Boolean //使用strict参数后,如果formData内的某个字段没有值,对应的描述元素将不会展示(包括标签文字)
543
544
  descriptionsItemProps:a-descriptions-item|el-descriptions-item的配置
544
545
  ```
545
546
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "general-basic-form",
3
- "version": "2.0.52",
3
+ "version": "2.0.53",
4
4
  "description": "",
5
- "main": "./dist/index.umd.cjs",
5
+ "main": "./src/index.ts",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "cross-env CURRENT_ENV=prod run-p type-check build-only",
@@ -46,16 +46,5 @@
46
46
  "vue": ">=3.3.4",
47
47
  "vue-router": ">=4.2.4"
48
48
  },
49
- "typings": "./dist/index.d.ts",
50
- "module": "./dist/index.js",
51
- "exports": {
52
- ".": {
53
- "import": "./dist/index.js",
54
- "require": "./dist/index.umd.cjs"
55
- },
56
- "./style": "./dist/style.css"
57
- },
58
- "files": [
59
- "/dist"
60
- ]
49
+ "typings": "./publish/index.d.ts"
61
50
  }
package/script/link.ts ADDED
@@ -0,0 +1,36 @@
1
+ /*
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2023-11-10 09:39:59
4
+ * @LastEditTime: 2023-11-15 18:04:19
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description: link处理流程
8
+ * @FilePath: \GeneralBasicForm\script\link.ts
9
+ *
10
+ */
11
+ import path from "path";
12
+ import fs from 'fs'
13
+ import chalk from 'chalk'
14
+ import { fileURLToPath } from 'url'
15
+ const __filenameNew = fileURLToPath(import.meta.url)
16
+ const __dirnameNew = path.dirname(__filenameNew)
17
+ const updateMain = () => {
18
+ try {
19
+ const packageTxt = fs.readFileSync(path.join(__dirnameNew, '../package.json'), 'utf8');
20
+ const packageJson = JSON.parse(packageTxt);
21
+ const mainDir = "./src/index.ts"
22
+ delete packageJson.files
23
+ delete packageJson.module
24
+ delete packageJson.exports
25
+ packageJson.typings = "./publish/index.d.ts"
26
+ packageJson.main = mainDir
27
+ const versionData = JSON.stringify(packageJson, null, 2);
28
+ fs.writeFileSync(path.join(__dirnameNew, '../package.json'), versionData, 'utf8');
29
+ console.log(chalk.green.bold('修改入口配置成功!当前入口路径为为:' + mainDir));
30
+ } catch (error) {
31
+ console.log(chalk.red.bold('修改入口配置出错:', error.toString()));
32
+ }
33
+
34
+ }
35
+
36
+ updateMain()
@@ -0,0 +1,45 @@
1
+ /*
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2023-11-10 09:39:59
4
+ * @LastEditTime: 2023-11-16 15:09:53
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description: unlink处理流程
8
+ * @FilePath: \GeneralBasicForm\script\unlink.ts
9
+ *
10
+ */
11
+ import path from "path";
12
+ import fs from 'fs'
13
+ import chalk from 'chalk'
14
+ import { fileURLToPath } from 'url'
15
+ const __filenameNew = fileURLToPath(import.meta.url)
16
+ const __dirnameNew = path.dirname(__filenameNew)
17
+ const updateMain = () => {
18
+ try {
19
+ const packageTxt = fs.readFileSync(path.join(__dirnameNew, '../package.json'), 'utf8');
20
+ const packageJson = JSON.parse(packageTxt);
21
+ const umdDir = "./dist/index.umd.cjs"
22
+ const esDir = "./dist/index.js"
23
+ packageJson.main = umdDir
24
+ packageJson.module = esDir
25
+ packageJson.exports = {
26
+ ".": {
27
+ "import": esDir,
28
+ "require": umdDir
29
+ },
30
+ "./style": "./dist/style.css"
31
+ }
32
+ packageJson.typings = "./dist/index.d.ts"
33
+ packageJson.files = [
34
+ "/dist"
35
+ ]
36
+ const versionData = JSON.stringify(packageJson, null, 2);
37
+ fs.writeFileSync(path.join(__dirnameNew, '../package.json'), versionData, 'utf8');
38
+ console.log(chalk.green.bold('修改入口配置成功!当前入口路径为为:' + umdDir));
39
+ } catch (error) {
40
+ console.log(chalk.red.bold('修改入口配置出错:', error.toString()));
41
+ }
42
+
43
+ }
44
+
45
+ updateMain()
@@ -0,0 +1,106 @@
1
+ <!--
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2023-12-08 17:45:01
4
+ * @LastEditTime: 2024-09-25 18:01:50
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description: 对展示描述列表的封装
8
+ * @FilePath: \GeneralBasicForm\src\Descriptions.vue
9
+ *
10
+ -->
11
+ <template>
12
+ <component :is="descriptions" :column="1" border class="form-width" v-bind="$attrs">
13
+ <component :is="descriptionsItem" v-for="(item, i) in renderFormItem" :key="item.prop" :label="item.label"
14
+ v-bind="item.descriptionsItemProps">
15
+ <RenderComponent v-if="item.render" :i="i" :render="item.render" :formData="formData"></RenderComponent>
16
+ <span v-else>
17
+ {{ formData[item.prop] }}
18
+ </span>
19
+ </component>
20
+ </component>
21
+ </template>
22
+
23
+ <script lang="ts" setup>
24
+ import type { PropType, FunctionalComponent, VNode } from "vue";
25
+ import { shallowRef, watch, ref } from "vue";
26
+ import type { ComponentType } from "./types/componentType"
27
+ import type { ItemType } from "./types/basicFrom";
28
+ const props = defineProps({
29
+ formData: {
30
+ type: Object,
31
+ required: true,
32
+ },
33
+ formItem: {
34
+ type: Array as unknown as PropType<ItemType[]>,
35
+ required: true,
36
+ },
37
+ componentType: {
38
+ type: String as unknown as PropType<ComponentType>,
39
+ default: "Element Plus"
40
+ },
41
+ strict: {
42
+ // 使用strict参数后,如果formData内的某个字段没有值,对应的描述元素将不会展示(包括标签文字)
43
+ type: Boolean,
44
+ default: false
45
+ },
46
+ });
47
+ const renderFormItem = ref<ItemType[]>([])
48
+ watch(
49
+ () => [props.formData, props.formItem],
50
+ ([NewFormData = {}, NewFormItem = <any>[]]) => {
51
+ let PhasedFormItem = NewFormItem
52
+ if (props.strict) {
53
+ // strict严格模式过滤formItem
54
+ // console.log(NewFormData)
55
+ // console.log(PhasedFormItem)
56
+ for (const key in NewFormData) {
57
+ if (Object.prototype.hasOwnProperty.call(NewFormData, key)) {
58
+ const element = NewFormData[key];
59
+ if (!element) {
60
+ PhasedFormItem = PhasedFormItem.filter((item) => {
61
+ return item.prop !== key
62
+ })
63
+ }
64
+ }
65
+ }
66
+
67
+
68
+ }
69
+ renderFormItem.value = PhasedFormItem
70
+ },
71
+ { immediate: true }
72
+ );
73
+ const descriptions = shallowRef("el-descriptions-item")
74
+ const descriptionsItem = shallowRef("descriptions-item")
75
+ switch (props.componentType) {
76
+ case "Element Plus":
77
+ descriptions.value = "el-descriptions-item"
78
+ descriptionsItem.value = "el-descriptions-item"
79
+ break;
80
+ case "Ant Design Vue":
81
+ descriptions.value = "a-descriptions"
82
+ descriptionsItem.value = "a-descriptions-item"
83
+ break;
84
+ default:
85
+ break;
86
+ }
87
+ type RenderComponentProps = {
88
+ i: any;
89
+ formData: Object;
90
+ render: (item: any) => VNode | String;
91
+ };
92
+ type Events = {};
93
+ // 函数直接返回VNode模板会识别成[object Promise],因此需要转换成函数式组件
94
+ const RenderComponent: FunctionalComponent<RenderComponentProps, Events> = (
95
+ props,
96
+ context
97
+ ) => {
98
+ const { i, render, formData } = props;
99
+ return render({
100
+ row: formData,
101
+ $index: i,
102
+ });
103
+ };
104
+ </script>
105
+
106
+ <style></style>
@@ -0,0 +1,277 @@
1
+ <!--
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2021-08-20 17:14:53
4
+ * @LastEditTime: 2024-09-04 17:18:32
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description:
8
+ * @FilePath: \GeneralBasicForm\src\GeneralBasicForm.vue
9
+ *
10
+ -->
11
+ /** 通用基本表单。用在表单页面搜索栏 */
12
+
13
+ <template>
14
+ <el-form
15
+ :model="queryParams"
16
+ ref="queryFormRef"
17
+ v-show="showSearch"
18
+ inline
19
+ label-position="left"
20
+ :label-width="labelWidth"
21
+ v-bind="$attrs"
22
+ >
23
+ <el-form-item
24
+ v-for="item in formItem"
25
+ :label="item.label"
26
+ :prop="item.prop"
27
+ :key="item.prop"
28
+ :rules="getItemRules(item)"
29
+ >
30
+ <Input v-if="/^input$/i.test(item.type)" :item="item" />
31
+ <Radio v-if="/^radio$/i.test(item.type)" :item="item" />
32
+ <Select v-if="/^select$/i.test(item.type)" :item="item" />
33
+ <Divider v-if="/^divider$/i.test(item.type)" :item="item" />
34
+ <Cascader v-if="/^cascader$/i.test(item.type)" :item="item" />
35
+ <Checkbox v-if="/^checkbox$/i.test(item.type)" :item="item" />
36
+ <DatePicker v-if="/^date-picker$/i.test(item.type)" :item="item" />
37
+ <InputNumber v-if="/^input-number$/i.test(item.type)" :item="item" />
38
+ <slot v-if="/^form-item-slot$/i.test(item.type)" :name="item.name"></slot>
39
+ <InputMobileVerification
40
+ v-if="/^input-mobile-verification$/i.test(item.type)"
41
+ :item="item"
42
+ />
43
+ <InputGraphicVerification
44
+ v-if="/^input-graphic-verification$/i.test(item.type)"
45
+ :item="item"
46
+ :key="item.key"
47
+ />
48
+ </el-form-item>
49
+ <slot></slot>
50
+ <el-form-item v-if="!formOnly">
51
+ <el-button
52
+ type="primary"
53
+ :size="size"
54
+ @click="handleQuery"
55
+ v-loading="formLoading"
56
+ >查询</el-button
57
+ >
58
+ <el-button :size="size" @click="resetQuery">重置</el-button>
59
+ </el-form-item>
60
+ <slot name="behind-the-button" />
61
+ </el-form>
62
+ </template>
63
+
64
+ <script lang="ts">
65
+ import { provide, ref, PropType, defineComponent, computed } from "vue";
66
+ import type { ItemType } from "./types/basicFrom";
67
+ import { useRoute } from "vue-router";
68
+ import Input from "./components/VBasic/input/index.vue";
69
+ import InputNumber from "./components/VBasic/input-number/index.vue";
70
+ import InputGraphicVerification from "./components/CustomCom/input-graphic-verification/index.vue";
71
+ import InputMobileVerification from "./components/CustomCom/input-mobile-verification/index.vue";
72
+ import Divider from "./components/VBasic/divider/index.vue";
73
+ import Radio from "./components/VBasic/radio/index.vue";
74
+ import Checkbox from "./components/VBasic/checkbox/index.vue";
75
+ import DatePicker from "./components/VBasic/date-picker/index.vue";
76
+ import Select from "./components/VBasic/select/index.vue";
77
+ import Cascader from "./components/VBasic/cascader/index.vue";
78
+ import { formLoadingKey } from "./injectKey";
79
+
80
+ export default defineComponent({
81
+ name: "GeneralBasicForm",
82
+ components: {
83
+ Input,
84
+ InputNumber,
85
+ InputGraphicVerification,
86
+ InputMobileVerification,
87
+ Divider,
88
+ Radio,
89
+ Checkbox,
90
+ DatePicker,
91
+ Select,
92
+ Cascader,
93
+ },
94
+ props: {
95
+ showSearch: {
96
+ // 是否展示所有元素
97
+ type: Boolean,
98
+ default: true,
99
+ },
100
+ loading: {
101
+ // 加载动画
102
+ type: Boolean,
103
+ default: false,
104
+ },
105
+ formOnly: {
106
+ // 是否只展示表单不展示按钮
107
+ type: Boolean,
108
+ default: false,
109
+ },
110
+ getList: {
111
+ // 查找数据调用的函数
112
+ type: Function,
113
+ default: () => {},
114
+ },
115
+ afterReset: {
116
+ // 在重置按钮点击完后但还没重新请求时触发的的函数
117
+ type: Function,
118
+ default: () => {},
119
+ },
120
+ formItem: {
121
+ // 定义表单的数据
122
+ type: Array as unknown as PropType<ItemType[]>,
123
+ default: [],
124
+ },
125
+ size: {
126
+ // 控制按钮大小
127
+ type: String,
128
+ default: "default",
129
+ },
130
+ labelWidth: {
131
+ // 表单文字宽度
132
+ type: String,
133
+ default: "90px",
134
+ },
135
+ noUrlParameters: {
136
+ // 不接受和不改变url的参数
137
+ type: Boolean,
138
+ default: () => false,
139
+ },
140
+ formData: {
141
+ // 外部传入的表单数据,用于回填
142
+ type: Object,
143
+ default: () => {},
144
+ },
145
+ noInputBlank: {
146
+ // 用于判断input框是否校验仅空格
147
+ type: Boolean,
148
+ default: () => false,
149
+ },
150
+ },
151
+ data() {
152
+ return {
153
+ formLoading: this.loading || false,
154
+ trimRegex: /\S/,
155
+ };
156
+ },
157
+ setup(props) {
158
+ const { size, noUrlParameters, getList } = props;
159
+ const route = useRoute();
160
+ const queryParams = ref({
161
+ ...(noUrlParameters ? {} : route?.query),
162
+ }); // form表单数据
163
+ provide(/* 注入名 */ "queryParams", /* 值 */ queryParams);
164
+ provide(/* 注入名 */ "size", /* 值 */ size);
165
+ provide(/* 注入名 */ "getList", /* 值 */ getList);
166
+ // const { formItem } = toRefs(props);
167
+ // const { formItem } = props;
168
+ // console.log(formItem);
169
+ // const queryParams = {};
170
+ // formItem.forEach((item) => {
171
+ // queryParams[item.prop] = "";
172
+ // });
173
+ return {
174
+ queryParams,
175
+ };
176
+ },
177
+ watch: {
178
+ formData: {
179
+ handler(val, oldVal) {
180
+ if (JSON.stringify(val) !== JSON.stringify(oldVal)) {
181
+ this.queryParams = {
182
+ ...(this.noUrlParameters ? {} : this.queryParams),
183
+ ...val,
184
+ };
185
+ }
186
+ // console.log(this.queryParams);
187
+ },
188
+ // watch 默认是懒执行的:仅当数据源变化时,才会执行回调。但在某些场景中,我们希望在创建侦听器时,立即执行一遍回调。举例来说,我们想请求一些初始数据,然后在相关状态更改时重新请求数据。
189
+ // https://cn.vuejs.org/guide/essentials/watchers.html#deep-watchers
190
+ immediate: true,
191
+ // deep: true,
192
+ },
193
+ queryParams: {
194
+ handler(val) {
195
+ this.$emit("update:formData", val);
196
+ },
197
+ deep: true,
198
+ },
199
+ loading(val) {
200
+ // console.log("loading", val);
201
+ if (this.formLoading === val) {
202
+ return;
203
+ }
204
+ this.formLoading = val;
205
+ },
206
+ formLoading(val) {
207
+ // console.log("formLoading", val);
208
+ if (this.loading === val) {
209
+ return;
210
+ }
211
+ this.$emit("update:loading", val);
212
+ },
213
+ },
214
+ provide() {
215
+ return {
216
+ // 显式提供一个计算属性
217
+ [formLoadingKey]: {
218
+ formLoading: computed(() => this.formLoading),
219
+ updateFormLoading: (val) => {
220
+ this.formLoading = val;
221
+ },
222
+ },
223
+ };
224
+ },
225
+ methods: {
226
+ /** 搜索按钮操作 */
227
+ handleQuery() {
228
+ const params = { page: 1, limit: 10 };
229
+ const searchParams = {
230
+ ...this.$route?.query,
231
+ ...this.queryParams,
232
+ ...params,
233
+ };
234
+ if (!this.noUrlParameters) {
235
+ this.$router.push({
236
+ query: { ...searchParams },
237
+ });
238
+ }
239
+ this.getList({
240
+ ...searchParams,
241
+ });
242
+ },
243
+ /** 重置按钮操作 */
244
+ async resetQuery() {
245
+ this.$refs.queryFormRef.resetFields();
246
+ const params = { page: 1 };
247
+ if (!this.noUrlParameters) {
248
+ await this.$router.push({
249
+ query: { ...params },
250
+ });
251
+ }
252
+ this.queryParams = {
253
+ ...(this.noUrlParameters ? {} : this.$route?.query),
254
+ };
255
+ this.afterReset();
256
+ this.handleQuery();
257
+ },
258
+ getItemRules(item: any) {
259
+ const { type, rules = [] } = item;
260
+ const newRules = [...rules];
261
+ if (this.noInputBlank && type === "input") {
262
+ newRules.push({
263
+ pattern: this.trimRegex,
264
+ message: "请输入(不能仅输入空格)",
265
+ trigger: "blur",
266
+ });
267
+ return newRules;
268
+ }
269
+
270
+ return newRules;
271
+ },
272
+ },
273
+ });
274
+ </script>
275
+
276
+ <style scoped>
277
+ </style>
@@ -0,0 +1,170 @@
1
+ <!--
2
+ * @Author: 陈德立*******419287484@qq.com
3
+ * @Date: 2023-12-05 15:09:03
4
+ * @LastEditTime: 2024-07-16 10:46:16
5
+ * @LastEditors: 陈德立*******419287484@qq.com
6
+ * @Github: https://github.com/Alan1034
7
+ * @Description: 公共的无限滚动列表
8
+ * @FilePath: \GeneralBasicForm\src\InfiniteScrollList.vue
9
+ *
10
+ -->
11
+ <template>
12
+ <el-checkbox-group
13
+ v-model="checkedList"
14
+ v-loading="loading"
15
+ v-bind="props"
16
+ v-if="props.checkbox"
17
+ >
18
+ <ul
19
+ v-infinite-scroll="loadList"
20
+ class="list"
21
+ :infinite-scroll-disabled="ifbottom"
22
+ >
23
+ <li v-for="i in list" :key="i[id]" class="list-item">
24
+ <el-checkbox :value="i[id]" class="checkbox"
25
+ >{{ i[name] }}
26
+ <ExtraComponent :i="i" v-if="props.extra"></ExtraComponent>
27
+ </el-checkbox>
28
+ </li>
29
+ </ul>
30
+ </el-checkbox-group>
31
+ <ul
32
+ v-infinite-scroll="loadList"
33
+ class="list"
34
+ :infinite-scroll-disabled="ifbottom"
35
+ v-else
36
+ v-bind="props"
37
+ >
38
+ <li v-for="i in list" :key="i[id]" class="list-item">
39
+ <div class="checkbox">
40
+ {{ i[name] }}
41
+ <ExtraComponent :i="i" v-if="props.extra"></ExtraComponent>
42
+ </div>
43
+ </li>
44
+ </ul>
45
+ </template>
46
+
47
+ <script lang="ts" setup>
48
+ import { ref, computed, watch } from "vue";
49
+ import type { PropType, FunctionalComponent, VNode } from "vue";
50
+ type SearchFunction = (page: Number) => Promise<[]>;
51
+ type ExtraFunction = "false" | ((item: any) => VNode | String);
52
+ const props = defineProps({
53
+ search: {
54
+ type: Function as PropType<SearchFunction>,
55
+ required: true,
56
+ },
57
+ checkbox: {
58
+ type: Boolean,
59
+ required: false,
60
+ },
61
+ id: {
62
+ type: String,
63
+ required: true,
64
+ },
65
+ name: {
66
+ type: String,
67
+ required: true,
68
+ },
69
+ extra: {
70
+ type: null as PropType<ExtraFunction>,
71
+ required: false,
72
+ },
73
+ defaultSelection: {
74
+ type: Array,
75
+ required: false,
76
+ },
77
+ });
78
+ const { search, id, name, extra } = props;
79
+ const list = ref<any[]>([]);
80
+ const page = ref(1);
81
+ const ifbottom = ref(false); //判断是否到底部,是的话就不再请求
82
+ const checkedList = ref<any[]>([]);
83
+ const loading = ref(false);
84
+ type ExtraComponentProps = {
85
+ i: any;
86
+ };
87
+ type Events = {};
88
+ // 函数直接返回VNode模板会识别成[object Promise],因此需要转换成函数式组件
89
+ const ExtraComponent: FunctionalComponent<ExtraComponentProps, Events> = (
90
+ props,
91
+ context
92
+ ) => {
93
+ const { i } = props;
94
+ // el-checkbox有固定高度,如果需要配置高度比较高,例如有换行的自定义extra,最好处理一下样式,例子:
95
+ // :deep(.el-checkbox) {
96
+ // padding: 6px 16px !important;
97
+ // display: flex;
98
+ // align-items: baseline;
99
+ // height: auto;
100
+ // }
101
+ return extra && extra !== "false" ? extra(i) : "";
102
+ };
103
+ const updateCheckedList = (newSelection: any[]) => {
104
+ checkedList.value = newSelection.map((item) => {
105
+ return typeof item === "object" ? item[id] : item;
106
+ });
107
+ };
108
+ watch(
109
+ () => props.defaultSelection,
110
+ (NewVal = [], oldVal = []) => {
111
+ updateCheckedList(NewVal);
112
+ },
113
+ { immediate: true }
114
+ );
115
+ const reset = () => {
116
+ lowReset();
117
+ checkedList.value = [];
118
+ };
119
+ const lowReset = () => {
120
+ page.value = 1;
121
+ list.value = [];
122
+ ifbottom.value = false;
123
+ };
124
+ const loadList = async () => {
125
+ if (loading.value) {
126
+ return;
127
+ }
128
+ if (ifbottom.value) {
129
+ return;
130
+ }
131
+ loading.value = true;
132
+ const resList = await search(page.value);
133
+ if (resList && resList.length > 0) {
134
+ list.value = [...list.value, ...resList];
135
+ page.value += 1;
136
+ } else {
137
+ ifbottom.value = true;
138
+ }
139
+ loading.value = false;
140
+ };
141
+ const refreshList = () => {
142
+ lowReset();
143
+ loadList();
144
+ };
145
+ const selectInfo =
146
+ computed(() =>
147
+ list.value.filter((item) => checkedList.value.includes(item[id]))
148
+ ) || {};
149
+ defineExpose({
150
+ reset,
151
+ lowReset,
152
+ loadList,
153
+ selectInfo,
154
+ list,
155
+ ifbottom,
156
+ refreshList,
157
+ });
158
+ </script>
159
+
160
+ <style lang="less" scoped>
161
+ .list {
162
+ height: 272px;
163
+ overflow: auto;
164
+ padding: 8px 0px;
165
+ .checkbox {
166
+ width: calc(100% - 32px);
167
+ padding: 0 16px;
168
+ }
169
+ }
170
+ </style>
Binary file