wui-components-v2 1.2.8 → 1.2.10

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.
@@ -4,13 +4,12 @@ import { useRouter } from 'uni-mini-router'
4
4
  import { onLoad } from '@dcloudio/uni-app'
5
5
  import type { ClassEditConfigs, Columns, Entities, Enums, Fields, Groups, rowActions } from '../../type'
6
6
  import ActionPopup from '../action-popup/action-popup.vue'
7
- import { actionDataSave, deleteData, editPageConfig } from '../../api/page'
7
+ import { actionDataSave, copyDataApi, deleteData, editPageConfig } from '../../api/page'
8
8
  import { useGlobalToast } from '../../composables/useGlobalToast'
9
9
  import { useGlobalMessage } from '../../composables/useGlobalMessage'
10
10
  import { comparator, generateHighResolutionID } from '../../utils/index'
11
11
  import ControlTypeSupportor from '../../utils/control-type-supportor'
12
12
  import { formatItemData } from '../../utils'
13
- import CopyButton from '../copy-button/copy-button.vue'
14
13
 
15
14
  defineOptions({
16
15
  name: 'CardBotomButtons',
@@ -161,6 +160,58 @@ function del() {
161
160
  })
162
161
  }
163
162
 
163
+ // 复制操作(原 copy-button 组件内联逻辑)
164
+ async function handleCopy() {
165
+ console.log(props.copyMode, 'copyMode')
166
+ // 复制操作:跳转新增页,仅复制基本信息(fieldMap),不带原 ID 和 relation 分组数据(如快递运单)
167
+ if (props.copyMode === 'editCopy') {
168
+ let fieldMapData = props.data.fieldMap
169
+ try {
170
+ const res: any = await editPageConfig(props.sourceId, props.code)
171
+ const entity = res?.dtmplConfig?.entity
172
+ if (entity?.fieldMap) fieldMapData = entity.fieldMap
173
+ } catch (e) {
174
+ console.log('[copy] 拉取完整实体失败,回退使用列表数据', e)
175
+ }
176
+ const copyEvent = generateHighResolutionID()
177
+ uni.setStorageSync(copyEvent, {
178
+ code: '',
179
+ fieldMap: fieldMapData,
180
+ arrayMap: {}, // 不复制 relation 分组数据(快递运单等需用户重新填写)
181
+ })
182
+ router.push(
183
+ `/pages/edit-page/index?sourceId=${props.sourceId}&id=&title=${props.item.title}&pageType=${props.pageType}&addEvent=${props.addEvent}&copyEvent=${copyEvent}`
184
+ )
185
+ return
186
+ } else if (props.copyMode === 'copyOnly') {
187
+ // 直接调用后端复制接口,复制当前行数据(服务端按 sourceId+code 生成新副本)
188
+ try {
189
+ await copyDataApi(props.sourceId, props.code)
190
+ uni.showToast({ title: '复制成功', icon: 'success' })
191
+ // 通知父组件刷新列表,使新复制的数据立即出现
192
+ props.zpaging?.reload?.()
193
+ } catch (e: any) {
194
+ console.log('[copy] 复制失败', e)
195
+ uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
196
+ }
197
+ return
198
+ } else {
199
+ // 默认复制模式:调用后端复制接口生成新副本,成功后跳转编辑页
200
+ try {
201
+ const res: any = await copyDataApi(props.sourceId, props.code)
202
+ const newCode = res?.entity?.code || res?.code || res?.data?.code
203
+ uni.showToast({ title: '复制成功', icon: 'success' })
204
+ router.push(
205
+ `/pages/edit-page/index?sourceId=${props.sourceId}&id=${newCode}&title=${props.item.title}&pageType=${props.pageType}&addEvent=${props.addEvent}`
206
+ )
207
+ } catch (e: any) {
208
+ console.log('[copy] 复制失败', e)
209
+ uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
210
+ }
211
+ return
212
+ }
213
+ }
214
+
164
215
  // 更多按钮数据
165
216
  interface Morebutns extends Omit<rowActions, ''> {
166
217
  actionType: string
@@ -252,13 +303,13 @@ console.log(props, '3333333333333')
252
303
  </wd-button>
253
304
  </template>
254
305
  </template>
255
- <CopyButton
306
+ <wd-button
256
307
  v-if="isShowAction !== false && props.item.buttons.includes('copy') && isActionVisible(props.buttonEditAction)"
257
- :data="props.data"
258
- :copy-mode="props.copyMode"
259
- :other-props="props"
260
- @refresh="props.zpaging?.reload?.()"
261
- />
308
+ size="small"
309
+ @click="handleCopy"
310
+ >
311
+ 复制
312
+ </wd-button>
262
313
  <wd-button
263
314
  v-if="
264
315
  isShowAction !== false && props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)
@@ -152,6 +152,7 @@ function initFormData() {
152
152
  }
153
153
  }
154
154
 
155
+ console.log('processedModels:', processedModels)
155
156
  model.value = {
156
157
  ...processedModels,
157
158
  }
@@ -415,10 +416,8 @@ watch(
415
416
  shouldMonitor.value?.forEach((item: any) => {
416
417
  const oldSnap = oldVal[item.id] || {}
417
418
  const newSnap = newVal[item.id] || {}
418
- const relChanged =
419
- item.relValueField && oldSnap.relValueField !== newSnap.relValueField
420
- const rel3Changed =
421
- item.relValueField3 && oldSnap.relValueField3 !== newSnap.relValueField3
419
+ const relChanged = item.relValueField && oldSnap.relValueField !== newSnap.relValueField
420
+ const rel3Changed = item.relValueField3 && oldSnap.relValueField3 !== newSnap.relValueField3
422
421
  if (relChanged || rel3Changed) {
423
422
  model.value[item.id] = ''
424
423
  }
@@ -854,6 +853,7 @@ console.log('clearValueMap', clearValueMap)
854
853
  :readonly="item.disabled || item.rowEditType === 'readonly'"
855
854
  :clearable="!item.disabled"
856
855
  :default-select-first="!!item.defaultSelectFirst"
856
+ :default-value="item.transDefaultValue || item.defaultValue"
857
857
  />
858
858
  </wd-form-item>
859
859
  <wd-form-item
@@ -873,6 +873,7 @@ console.log('clearValueMap', clearValueMap)
873
873
  :readonly="item.disabled || item.rowEditType === 'readonly'"
874
874
  :clearable="!item.disabled"
875
875
  :default-select-first="!!item.defaultSelectFirst"
876
+ :default-value="item.transDefaultValue || item.defaultValue"
876
877
  />
877
878
  </wd-form-item>
878
879
  <wd-form-item
@@ -894,6 +895,7 @@ console.log('clearValueMap', clearValueMap)
894
895
  :readonly="item.disabled || item.rowEditType === 'readonly'"
895
896
  :clearable="!item.disabled"
896
897
  :default-select-first="!!item.defaultSelectFirst"
898
+ :default-value="item.transDefaultValue || item.defaultValue"
897
899
  fold-card-model="complex"
898
900
  />
899
901
  </wd-form-item>
@@ -23,6 +23,7 @@ const props = withDefaults(
23
23
  readonly?: boolean // 只读模式,禁止打开弹窗
24
24
  clearable?: boolean // 是否显示清空按钮
25
25
  defaultSelectFirst?: boolean // 是否默认选择第一项
26
+ defaultValue?: string | string[] // 字段配置的默认值(格式同 modelValue,可单值或数组)
26
27
  }>(),
27
28
  {
28
29
  title: '',
@@ -33,6 +34,7 @@ const props = withDefaults(
33
34
  readonly: false,
34
35
  clearable: true,
35
36
  defaultSelectFirst: false,
37
+ defaultValue: '',
36
38
  }
37
39
  )
38
40
  console.log(props, '3333333333333333333')
@@ -167,18 +169,61 @@ const hasInitialized = ref(false)
167
169
  // ★ 是否已完成默认首项选中
168
170
  const hasDefaultSelected = ref(false)
169
171
 
170
- // ★ 默认选择第一项:数据加载完成后自动选中第一条并回显
172
+ // 解析 $$user. 占位符:取 `$$user.` 之后的字段名,从本地 userInfo.extInfo.fieldMap 取对应值
173
+ const resolveUserValue = (raw: string): string => {
174
+ if (typeof raw !== 'string' || !raw.includes('$$user.')) return raw
175
+ const key = raw.split('$$user.')[1]
176
+ const { extInfo = {} } = uni.getStorageSync('userInfo') || {}
177
+ const fieldMap = extInfo.fieldMap || {}
178
+ const val = fieldMap[key]
179
+ return val !== undefined && val !== null ? String(val) : ''
180
+ }
181
+
182
+ // ★ 预选默认值来源:props.defaultValue(父组件传入) > 后端配置 primaryCriterion.transDefaultValue/defaultValue
183
+ const getDefaultValue = (): string | string[] => {
184
+ if (props.defaultValue) return props.defaultValue
185
+ const criterion = config.value.primaryCriterion
186
+ if (criterion?.transDefaultValue) return criterion.transDefaultValue
187
+ if (criterion?.defaultValue) return criterion.defaultValue
188
+ return ''
189
+ }
190
+
191
+ // ★ 默认选择:数据加载完成后按「默认值」或「第一项」预选并回显
171
192
  watch(datas, val => {
172
- if (!props.defaultSelectFirst || !val?.length || hasDefaultSelected.value || Object.keys(selectData.value).length > 0)
173
- return
174
- const first = val[0]
175
- selectData.value[first.code] = `${first.code}@R@${first.fieldMap[config.value.primaryColumn.sourceId]}`
176
- const result =
193
+ if (!val?.length || hasDefaultSelected.value || Object.keys(selectData.value).length > 0) return
194
+
195
+ const buildResult = () =>
177
196
  props.extControlType === 'relselect' || props.extControlType === 'relselect-extdis'
178
- ? selectData.value[first.code]
197
+ ? Object.values(selectData.value)[0]
179
198
  : Object.values(selectData.value)
180
- emit('update:modelValue', result)
181
- hasDefaultSelected.value = true
199
+
200
+ // 1) 字段/后端配置的默认值:按 code 在已加载数据中匹配预选
201
+ const def = getDefaultValue()
202
+ if (def) {
203
+ const codes = (Array.isArray(def) ? def : [def]).map(c => resolveUserValue(String(c)))
204
+ const matched = codes
205
+ .map(c => {
206
+ const code = typeof c === 'string' ? c.split('@R@')[0] : ''
207
+ return val.find(item => item.code === code)
208
+ })
209
+ .filter(Boolean) as Entities[]
210
+ if (matched.length) {
211
+ matched.forEach(item => {
212
+ selectData.value[item.code] = `${item.code}@R@${item.fieldMap[config.value.primaryColumn.sourceId]}`
213
+ })
214
+ emit('update:modelValue', buildResult())
215
+ hasDefaultSelected.value = true
216
+ return
217
+ }
218
+ }
219
+
220
+ // 2) 兜底:自动选第一项
221
+ if (props.defaultSelectFirst) {
222
+ const first = val[0]
223
+ selectData.value[first.code] = `${first.code}@R@${first.fieldMap[config.value.primaryColumn.sourceId]}`
224
+ emit('update:modelValue', buildResult())
225
+ hasDefaultSelected.value = true
226
+ }
182
227
  })
183
228
 
184
229
  // 获取页面配置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
@@ -1,73 +0,0 @@
1
- <template>
2
- <view size="small" @click="handleCopy" class="bg-[#1c64fd] text-white px-[12rpx] leading-[32rpx] rounded-[4px]">
3
- {{ '复制' }}
4
- </view>
5
- </template>
6
- <script setup lang="ts">
7
- import { editPageConfig, copyDataApi } from '../../api/page'
8
- import { generateHighResolutionID } from '../../utils'
9
-
10
- const props = defineProps<{
11
- copyMode?: string
12
- otherProps: any
13
- }>()
14
- const emit = defineEmits<{ (e: 'refresh'): void }>()
15
- const router = useRouter()
16
-
17
- async function handleCopy() {
18
- console.log(props.copyMode, 'copyMode')
19
- const { otherProps } = props
20
- // 复制操作:跳转新增页,仅复制基本信息(fieldMap),不带原 ID 和 relation 分组数据(如快递运单)
21
- if (props.copyMode === 'editOnly') {
22
- // 优先用编辑同款接口拉取完整 fieldMap(含关联选择字段值如基地名称/快递公司),失败回退列表行数据
23
- let fieldMapData = otherProps.data.fieldMap
24
- try {
25
- const res: any = await editPageConfig(otherProps.sourceId, otherProps.code)
26
- const entity = res?.dtmplConfig?.entity
27
- if (entity?.fieldMap) fieldMapData = entity.fieldMap
28
- } catch (e) {
29
- console.log('[copy] 拉取完整实体失败,回退使用列表数据', e)
30
- }
31
- // 生成复制标识:URL 带 copyEvent 区分"复制新增";存储以 copyEvent 为 key,仅本次复制可读,不污染普通新增
32
- const copyEvent = generateHighResolutionID()
33
- uni.setStorageSync(copyEvent, {
34
- code: '',
35
- fieldMap: fieldMapData,
36
- arrayMap: {}, // 不复制 relation 分组数据(快递运单等需用户重新填写)
37
- })
38
- router.push(
39
- `/pages/edit-page/index?sourceId=${otherProps.sourceId}&id=&title=${otherProps.item.title}&pageType=${otherProps.pageType}&addEvent=${otherProps.addEvent}&copyEvent=${copyEvent}`
40
- )
41
- return
42
- } else if (props.copyMode === 'copyOnly') {
43
- // 直接调用后端复制接口,复制当前行数据(服务端按 sourceId+code 生成新副本)
44
- try {
45
- await copyDataApi(otherProps.sourceId, otherProps.code)
46
- uni.showToast({ title: '复制成功', icon: 'success' })
47
- // 通知父组件刷新列表,使新复制的数据立即出现
48
- emit('refresh')
49
- } catch (e: any) {
50
- console.log('[copy] 复制失败', e)
51
- uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
52
- }
53
- return
54
- } else {
55
- // 默认复制模式:调用后端复制接口生成新副本,成功后跳转编辑页
56
- try {
57
- const res: any = await copyDataApi(otherProps.sourceId, otherProps.code)
58
- // 复制接口返回新副本的编码,按后端实际返回结构取(常见字段已兼容)
59
- const newCode = res?.entity?.code || res?.code || res?.data?.code
60
- uni.showToast({ title: '复制成功', icon: 'success' })
61
- router.push(
62
- `/pages/edit-page/index?sourceId=${otherProps.sourceId}&id=${newCode}&title=${otherProps.item.title}&pageType=${otherProps.pageType}&addEvent=${otherProps.addEvent}`
63
- )
64
- } catch (e: any) {
65
- console.log('[copy] 复制失败', e)
66
- uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
67
- }
68
- return
69
- }
70
- }
71
- </script>
72
-
73
- <style scoped></style>