wui-components-v2 1.1.95 → 1.1.96

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/api/core/index.ts CHANGED
@@ -53,7 +53,8 @@ function request(options: RequestOptions): Promise<any> {
53
53
  ...requestOptions,
54
54
  success: (res: UniApp.RequestSuccessCallbackResult) => {
55
55
  console.log('res111111', res)
56
- const { statusCode, data } = res
56
+ const { statusCode } = res
57
+ const data = res.data as any
57
58
 
58
59
  // 细分HTTP状态码错误处理,移除200-300区间整体判断
59
60
  if (statusCode === 401) {
@@ -85,11 +86,10 @@ function request(options: RequestOptions): Promise<any> {
85
86
  return
86
87
  }
87
88
 
88
- // 业务状态错误判断
89
+ // 业务状态错误判断:仅业务层面的失败(如校验不通过、数据不存在等),
90
+ // 与登录态无关,不应清除 token,否则会误判为需要重新登录
89
91
  if (data.status === 'error') {
90
92
  uni.showToast({ title: data.message || '操作失败', icon: 'none' })
91
- uni.removeStorageSync('token')
92
- uni.removeStorageSync('TOKEN')
93
93
  reject(res)
94
94
  return
95
95
  }
@@ -97,7 +97,7 @@ function request(options: RequestOptions): Promise<any> {
97
97
  // 全部校验通过,返回原始业务data
98
98
  resolve(data)
99
99
  },
100
- fail: (err: UniApp.RequestFailCallbackResult) => {
100
+ fail: (err: any) => {
101
101
  uni.showToast({ title: '网络请求失败,请检查网络或接口地址', icon: 'none' })
102
102
  reject(err)
103
103
  },
package/api/page.ts CHANGED
@@ -9,15 +9,16 @@ interface PageConfig {
9
9
  }
10
10
  // 列表页面配置
11
11
  export async function pageConfig(sourceId: string): Promise<PageConfig> {
12
- const res = await req({url: `/v3/ltmpl/config?sourceId=${sourceId}`})||{}
13
- const {ltmplConfig={}}=res
14
- const {extDisplayConfig={}}=ltmplConfig
15
- return { //配置结构调整
12
+ const res = (await req({ url: `/v3/ltmpl/config?sourceId=${sourceId}` })) || {}
13
+ const { ltmplConfig = {} } = res
14
+ const { extDisplayConfig = {} } = ltmplConfig
15
+ return {
16
+ //配置结构调整
16
17
  ...res,
17
- ltmplConfig:{
18
+ ltmplConfig: {
18
19
  ...ltmplConfig,
19
- ...extDisplayConfig
20
- }
20
+ ...extDisplayConfig,
21
+ },
21
22
  }
22
23
  }
23
24
 
@@ -50,7 +51,13 @@ export function editPageConfig(sourceId: string, mianCode: string) {
50
51
 
51
52
  //
52
53
  // 新增/编辑页面提交保存
53
- export function editPageDataSave(sourceId: string, id: string = '', data: any, mainCode: string = '', actionId: string = '') {
54
+ export function editPageDataSave(
55
+ sourceId: string,
56
+ id: string = '',
57
+ data: any,
58
+ mainCode: string = '',
59
+ actionId: string = ''
60
+ ) {
54
61
  return req({
55
62
  url: `/v3/dtmpl/data`,
56
63
  method: 'POST',
@@ -112,6 +119,17 @@ export function deleteData(sourceId: string, code: string) {
112
119
  method: 'DELETE',
113
120
  })
114
121
  }
122
+ // 复制数据(copyonly 模式):直接调用后端复制接口复制当前行
123
+ export function copyDataApi(sourceId: string, code: string) {
124
+ return req({
125
+ url: `/v3/mstruc/copy-data`,
126
+ method: 'POST',
127
+ data: {
128
+ sourceId,
129
+ code,
130
+ },
131
+ })
132
+ }
115
133
 
116
134
  // 关联字段联动:通过 relValueField 下选中值请求默认值
117
135
  // relValueField 下存在 extRefPageId 时请求 /v3/ltmpl/top-data,
@@ -10,6 +10,7 @@ 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'
13
14
 
14
15
  defineOptions({
15
16
  name: 'CardBotomButtons',
@@ -35,6 +36,7 @@ const props = defineProps<{
35
36
  * 不传或为 true 时显示;传 false 时整段隐藏。
36
37
  */
37
38
  isShowAction?: boolean
39
+ copyMode?: string
38
40
  }>()
39
41
  const toast = useGlobalToast()
40
42
  const message = useGlobalMessage()
@@ -202,29 +204,6 @@ const morebutns = computed(() => {
202
204
 
203
205
  // 点击操作按钮
204
206
  async function select({ item }: { item: any }) {
205
- // 复制操作:跳转新增页,仅复制基本信息(fieldMap),不带原 ID 和 relation 分组数据(如快递运单)
206
- if (item.title.includes('复制')) {
207
- // 优先用编辑同款接口拉取完整 fieldMap(含关联选择字段值如基地名称/快递公司),失败回退列表行数据
208
- let fieldMapData = props.data.fieldMap
209
- try {
210
- const res: any = await editPageConfig(props.sourceId, props.code)
211
- const entity = res?.dtmplConfig?.entity
212
- if (entity?.fieldMap) fieldMapData = entity.fieldMap
213
- } catch (e) {
214
- console.log('[copy] 拉取完整实体失败,回退使用列表数据', e)
215
- }
216
- // 生成复制标识:URL 带 copyEvent 区分"复制新增";存储以 copyEvent 为 key,仅本次复制可读,不污染普通新增
217
- const copyEvent = generateHighResolutionID()
218
- uni.setStorageSync(copyEvent, {
219
- code: '',
220
- fieldMap: fieldMapData,
221
- arrayMap: {}, // 不复制 relation 分组数据(快递运单等需用户重新填写)
222
- })
223
- router.push(
224
- `/pages/edit-page/index?sourceId=${props.sourceId}&id=&title=${props.item.title}&pageType=${props.pageType}&addEvent=${props.addEvent}&copyEvent=${copyEvent}`
225
- )
226
- return
227
- }
228
207
  if (item.title.includes('评价') && item.actionType === 'rowActions') {
229
208
  return action(item)
230
209
  }
@@ -273,9 +252,17 @@ console.log(props, '3333333333333')
273
252
  </wd-button>
274
253
  </template>
275
254
  </template>
276
-
255
+ <CopyButton
256
+ 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
+ />
277
262
  <wd-button
278
- v-if="isShowAction !== false && props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)"
263
+ v-if="
264
+ isShowAction !== false && props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)
265
+ "
279
266
  size="small"
280
267
  @click="edit()"
281
268
  >
@@ -283,7 +270,11 @@ console.log(props, '3333333333333')
283
270
  </wd-button>
284
271
  <wd-button v-if="props.item.buttons.includes('detail')" size="small" type="info" @click="detail()">详情</wd-button>
285
272
  <wd-button
286
- v-if="isShowAction !== false && props.item.buttons.includes('singleDelete') && isActionVisible(props.buttonDeleteAction)"
273
+ v-if="
274
+ isShowAction !== false &&
275
+ props.item.buttons.includes('singleDelete') &&
276
+ isActionVisible(props.buttonDeleteAction)
277
+ "
287
278
  size="small"
288
279
  type="danger"
289
280
  @click="del()"
@@ -0,0 +1,71 @@
1
+ <template>
2
+ <wd-button size="small" @click="handleCopy">{{ '复制' }}</wd-button>
3
+ </template>
4
+ <script setup lang="ts">
5
+ import { editPageConfig, copyDataApi } from '@/core-components/api/page'
6
+ import { generateHighResolutionID } from '@/core-components/utils'
7
+
8
+ const props = defineProps<{
9
+ copyMode?: string
10
+ otherProps: any
11
+ }>()
12
+ const emit = defineEmits<{ (e: 'refresh'): void }>()
13
+ const router = useRouter()
14
+
15
+ async function handleCopy() {
16
+ console.log(props.copyMode, 'copyMode')
17
+ const { otherProps } = props
18
+ // 复制操作:跳转新增页,仅复制基本信息(fieldMap),不带原 ID 和 relation 分组数据(如快递运单)
19
+ if (props.copyMode === 'editOnly') {
20
+ // 优先用编辑同款接口拉取完整 fieldMap(含关联选择字段值如基地名称/快递公司),失败回退列表行数据
21
+ let fieldMapData = otherProps.data.fieldMap
22
+ try {
23
+ const res: any = await editPageConfig(otherProps.sourceId, otherProps.code)
24
+ const entity = res?.dtmplConfig?.entity
25
+ if (entity?.fieldMap) fieldMapData = entity.fieldMap
26
+ } catch (e) {
27
+ console.log('[copy] 拉取完整实体失败,回退使用列表数据', e)
28
+ }
29
+ // 生成复制标识:URL 带 copyEvent 区分"复制新增";存储以 copyEvent 为 key,仅本次复制可读,不污染普通新增
30
+ const copyEvent = generateHighResolutionID()
31
+ uni.setStorageSync(copyEvent, {
32
+ code: '',
33
+ fieldMap: fieldMapData,
34
+ arrayMap: {}, // 不复制 relation 分组数据(快递运单等需用户重新填写)
35
+ })
36
+ router.push(
37
+ `/pages/edit-page/index?sourceId=${otherProps.sourceId}&id=&title=${otherProps.item.title}&pageType=${otherProps.pageType}&addEvent=${otherProps.addEvent}&copyEvent=${copyEvent}`
38
+ )
39
+ return
40
+ } else if (props.copyMode === 'copyOnly') {
41
+ // 直接调用后端复制接口,复制当前行数据(服务端按 sourceId+code 生成新副本)
42
+ try {
43
+ await copyDataApi(otherProps.sourceId, otherProps.code)
44
+ uni.showToast({ title: '复制成功', icon: 'success' })
45
+ // 通知父组件刷新列表,使新复制的数据立即出现
46
+ emit('refresh')
47
+ } catch (e: any) {
48
+ console.log('[copy] 复制失败', e)
49
+ uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
50
+ }
51
+ return
52
+ } else {
53
+ // 默认复制模式:调用后端复制接口生成新副本,成功后跳转编辑页
54
+ try {
55
+ const res: any = await copyDataApi(otherProps.sourceId, otherProps.code)
56
+ // 复制接口返回新副本的编码,按后端实际返回结构取(常见字段已兼容)
57
+ const newCode = res?.entity?.code || res?.code || res?.data?.code
58
+ uni.showToast({ title: '复制成功', icon: 'success' })
59
+ router.push(
60
+ `/pages/edit-page/index?sourceId=${otherProps.sourceId}&id=${newCode}&title=${otherProps.item.title}&pageType=${otherProps.pageType}&addEvent=${otherProps.addEvent}`
61
+ )
62
+ } catch (e: any) {
63
+ console.log('[copy] 复制失败', e)
64
+ uni.showToast({ title: e?.data?.message || '复制失败', icon: 'error' })
65
+ }
66
+ return
67
+ }
68
+ }
69
+ </script>
70
+
71
+ <style scoped></style>
@@ -15,15 +15,21 @@ import { useEnums } from '../../composables/useEnumes'
15
15
  defineOptions({
16
16
  name: 'WuiList',
17
17
  })
18
- defineProps<{
19
- isShowAction?: boolean
20
- detailButtonHandle?: (data: Entities) => void
21
- /**
22
- * 折叠前展示的数据条数,透传给 foldCard。
23
- * 不传时默认 2;传 0 表示只显示标题、不展示任何字段数据。
24
- */
25
- collapseNum?: number
26
- }>()
18
+ withDefaults(
19
+ defineProps<{
20
+ isShowAction?: boolean
21
+ detailButtonHandle?: (data: Entities) => void
22
+ /**
23
+ * 折叠前展示的数据条数,透传给 foldCard。
24
+ * 不传时默认 2;传 0 表示只显示标题、不展示任何字段数据。
25
+ */
26
+ collapseNum?: number
27
+ }>(),
28
+ {
29
+ // 操作按钮区域(编辑/删除/morebutns)默认显示
30
+ isShowAction: true,
31
+ }
32
+ )
27
33
 
28
34
  const Zpaging = ref<any>(null)
29
35
  const config = ref<Config>({
@@ -76,7 +82,6 @@ const pageType = ref('')
76
82
  const mainCode = ref('')
77
83
  const addEvent = generateHighResolutionID() // 全局事件名称
78
84
  onLoad((option: any) => {
79
- console.log(option)
80
85
  sourceId.value = option.sourceId
81
86
  pageTitle.value = option.title
82
87
  pageType.value = option.pageType
@@ -243,6 +248,7 @@ function tabSearchClick(data: any) {
243
248
  :page-type="pageType"
244
249
  :data="item"
245
250
  :is-show-action="isShowAction"
251
+ :copy-mode="config.copyMode"
246
252
  />
247
253
  </template>
248
254
  </productCard>
@@ -282,6 +288,7 @@ function tabSearchClick(data: any) {
282
288
  :button-delete-action="config.buttonDeleteAction"
283
289
  :button-edit-action="config.buttonEditAction"
284
290
  :is-show-action="isShowAction"
291
+ :copy-mode="config.copyMode"
285
292
  />
286
293
  </template>
287
294
  </foldCard2>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.1.95",
3
+ "version": "1.1.96",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
package/type.ts CHANGED
@@ -16,12 +16,11 @@ export type Comparator =
16
16
  | 'noGreater'
17
17
  | 'Less'
18
18
  | 'Greater'
19
- | 'none1' | 'none1n'
19
+ | 'none1'
20
+ | 'none1n'
20
21
 
21
22
  // tab字段配置
22
- export interface Split2TabCriterias extends Fields {
23
-
24
- }
23
+ export interface Split2TabCriterias extends Fields {}
25
24
 
26
25
  // 列表字段配置
27
26
  export interface Columns {
@@ -30,7 +29,6 @@ export interface Columns {
30
29
  sourceId: string
31
30
  mstrucId: string
32
31
  title?: string
33
-
34
32
  }
35
33
 
36
34
  // 动作按钮配置
@@ -60,6 +58,7 @@ export interface Config extends Groups {
60
58
  split2TabCriterias?: Split2TabCriterias[]
61
59
  extShowConfig?: { [key: string]: any }
62
60
  extDisplayConfig?: { [key: string]: any }
61
+ copyMode?: string
63
62
  }
64
63
 
65
64
  // 列表数据
@@ -122,7 +121,6 @@ export interface Groups {
122
121
 
123
122
  export interface Entity extends Entities {
124
123
  arrayMap: { [key: string]: Entities[] }
125
-
126
124
  }
127
125
 
128
126
  // 编辑页面配置