el-plus-crud 0.1.19 → 0.1.21

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.
@@ -87,6 +87,8 @@ const multipleTableRef = ref()
87
87
 
88
88
  // 存储的值
89
89
  const selectData = reactive([] as ILinkItem[])
90
+ // 存储历史选中-取消后要还原
91
+ const selectOldData = reactive([] as ILinkItem[])
90
92
 
91
93
  /**
92
94
  * 处理点击事件
@@ -97,6 +99,8 @@ function handelVisibleChange(val: any) {
97
99
  selectRef.value.blur()
98
100
  isShowDialog.value = true
99
101
  selectList.value = cloneDeep(selectData.map((item) => item.dataItem))
102
+ // 这里存储一下老数据
103
+ selectOldData.splice(0, selectOldData.length, ...selectData)
100
104
  }
101
105
  }
102
106
 
@@ -149,6 +153,8 @@ function handelTagRemove(item: ILinkItem) {
149
153
  */
150
154
  function cancel() {
151
155
  isShowDialog.value = false
156
+ // 这里重置一下老数据
157
+ selectData.splice(0, selectData.length, ...selectOldData)
152
158
  }
153
159
 
154
160
  /**
@@ -204,6 +210,27 @@ watch(
204
210
  { deep: true, immediate: true }
205
211
  )
206
212
 
213
+ watch(
214
+ () => props.modelValue,
215
+ () => {
216
+ selectData.splice(0, selectData.length)
217
+ values.splice(0, values.length)
218
+ // 这里默认选中
219
+ if (props.modelValue && Array.isArray(props.modelValue)) {
220
+ const [ids, names] = props.modelValue as Array<string[]>
221
+ if (ids.length > 0 && ids.length === names.length) {
222
+ ids.map((id, i) => {
223
+ // 构建选中数据
224
+ selectData.push({ label: names[i], value: id, dataItem: { [props.desc.lkey]: names[i], [vkey.value]: id } })
225
+ values.push(id)
226
+ })
227
+ }
228
+ }
229
+ options.splice(0, options.length, ...selectData)
230
+ },
231
+ { deep: true, immediate: true }
232
+ )
233
+
207
234
  onMounted(async () => {})
208
235
  </script>
209
236
  <style lang="scss" scoped>
@@ -123,6 +123,18 @@ const selectUser = reactive([] as Array<ILinkItem>)
123
123
  const selectOptions = reactive([] as any[])
124
124
  const selectAttrs = ref({})
125
125
 
126
+ // 左边列表idkey namekey
127
+ const lIdKey = ref(props.desc?.lIdKey || 'id')
128
+ const lNameKey = ref(props.desc?.lNameKey || 'name')
129
+ // 右边列表idkey namekey
130
+ const rIdKey = ref(props.desc?.rIdKey || 'userId')
131
+ const rNameKey = ref(props.desc?.rNameKey || 'nickname')
132
+
133
+ // 查询左边列表idKey
134
+ const lQueryIdKey = ref(props.desc?.lQueryIdKey || 'deptId')
135
+ // 组织架构列表
136
+ const deptDataList = ref((props.desc?.deptDataList || []) as any[])
137
+
126
138
  /**
127
139
  * 处理自定义请求
128
140
  * @param param
@@ -142,15 +154,20 @@ const multipleTableRef = ref()
142
154
  const tableData = computed(() => {
143
155
  const tempList = [] as ILinkItem[]
144
156
  // 遍历组织架构数据
145
- let tempData = cloneDeep(globalData[defaultConf.form?.linkUser?.deptListKey || ''])
157
+ let tempData = [] as any[]
158
+ if (deptDataList.value.length) {
159
+ tempData = deptDataList.value
160
+ } else {
161
+ tempData = cloneDeep(globalData[defaultConf.form?.linkUser?.deptListKey || ''])
162
+ }
146
163
  if (deptTreeIndex.value && deptTreeIndex.value.length > 0) {
147
164
  deptTreeIndex.value.map((item) => {
148
165
  tempData = tempData[item].children || []
149
166
  })
150
167
  }
151
- tempData.map((item: any) => tempList.push({ type: 2, label: item.name, value: item.id }))
168
+ tempData.map((item: any) => tempList.push({ type: 2, label: item[lNameKey.value], value: item[lIdKey.value] }))
152
169
  // 遍历用户数据
153
- tableUserData.value.map((item) => tempList.push({ type: 1, label: item.nickname, value: item.userId }))
170
+ tableUserData.value.map((item) => tempList.push({ type: 1, label: item[rNameKey.value], value: item[rIdKey.value] }))
154
171
 
155
172
  // 这里默认选中
156
173
  nextTick(() => {
@@ -228,7 +245,7 @@ function handelSelectChange(val: any) {
228
245
  async function selectRemote(nickname: string) {
229
246
  if (nickname.length > 0) {
230
247
  return ((await defaultConf.form?.linkUser?.getUserList({ nickname, current: 1, size: 10, enabled: 1 })) as any).records?.map((item: any) => {
231
- return { value: item.userId, label: item.nickname }
248
+ return { value: item[rIdKey.value], label: item[rNameKey.value] }
232
249
  })
233
250
  }
234
251
  return []
@@ -240,7 +257,7 @@ async function selectRemote(nickname: string) {
240
257
  */
241
258
  async function goInto(item: ILinkItem, index: number) {
242
259
  // 查询机构用户
243
- tableUserData.value = (await defaultConf.form?.linkUser?.getUserList({ deptId: item.value, size: 999 })).records as any[]
260
+ tableUserData.value = (await defaultConf.form?.linkUser?.getUserList({ [lQueryIdKey.value]: item.value, size: 999 })).records as any[]
244
261
  deptTreeIndex.value.push(index)
245
262
  deptTreeItems.value.push(item)
246
263
  }
@@ -251,7 +268,7 @@ async function goInto(item: ILinkItem, index: number) {
251
268
  */
252
269
  async function goIndex(index: number) {
253
270
  // 查询机构用户
254
- tableUserData.value = index >= 0 ? ((await defaultConf.form?.linkUser?.getUserList({ deptId: deptTreeItems.value[index].value, size: 999 })).records as any[]) : []
271
+ tableUserData.value = index >= 0 ? ((await defaultConf.form?.linkUser?.getUserList({ [lQueryIdKey.value]: deptTreeItems.value[index].value, size: 999 })).records as any[]) : []
255
272
  deptTreeIndex.value.splice(index + 1)
256
273
  deptTreeItems.value.splice(index + 1)
257
274
  }
@@ -463,6 +480,10 @@ onMounted(async () => {
463
480
  padding: 0 10px;
464
481
  margin-bottom: 20px;
465
482
  cursor: pointer;
483
+ span {
484
+ line-height: 24px;
485
+ color: var(--el-color-primary);
486
+ }
466
487
  }
467
488
  }
468
489
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "el-plus-crud",
3
3
  "description": "采用Vue3 + TS,封装的element-plus数据驱动表单、列表组件",
4
4
  "author": "K.D.Jack",
5
- "version": "0.1.19",
5
+ "version": "0.1.21",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",