wui-components-v2 1.2.74 → 1.2.77
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/components/audio-play/audio-play.vue +31 -28
- package/components/card-botom-buttons/card-botom-buttons.vue +2 -0
- package/components/custom-date-picker/custom-date-picker.vue +55 -4
- package/components/form-control/form-control.vue +15 -1
- package/components/global-message/global-message.vue +22 -18
- package/components/label-value/label-value.vue +7 -2
- package/components/report-table/report-table.vue +1 -1
- package/components/wui-details-page/wui-details-page.vue +16 -1
- package/components/wui-edit-page/wui-edit-page.vue +57 -22
- package/components/wui-list/wui-list.vue +32 -2
- package/components/wui-user/wui-user.vue +3 -6
- package/composables/useGlobalMessage.ts +32 -0
- package/package.json +1 -1
|
@@ -161,10 +161,15 @@ onMounted(() => {
|
|
|
161
161
|
<template>
|
|
162
162
|
<view class="mini-audio-player">
|
|
163
163
|
<!-- 播放/暂停按钮 -->
|
|
164
|
-
<
|
|
165
|
-
|
|
166
|
-
<
|
|
167
|
-
|
|
164
|
+
<view class="mini-play-btn" :style="{ background: primary }" @click="togglePlay">
|
|
165
|
+
<!-- 播放中:显示暂停符号(两条竖杠) -->
|
|
166
|
+
<view v-if="isPlaying" class="pause-icon">
|
|
167
|
+
<view class="pause-bar" />
|
|
168
|
+
<view class="pause-bar" />
|
|
169
|
+
</view>
|
|
170
|
+
<!-- 未播放:显示三角播放符号 -->
|
|
171
|
+
<view v-else class="play-triangle" />
|
|
172
|
+
</view>
|
|
168
173
|
|
|
169
174
|
<!-- 时间显示 -->
|
|
170
175
|
<text class="time-display">
|
|
@@ -201,44 +206,42 @@ onMounted(() => {
|
|
|
201
206
|
background: #1890ff;
|
|
202
207
|
border: none;
|
|
203
208
|
padding: 0;
|
|
209
|
+
margin: 0;
|
|
204
210
|
display: flex;
|
|
205
211
|
align-items: center;
|
|
206
212
|
justify-content: center;
|
|
207
213
|
margin-right: 8px;
|
|
214
|
+
flex-shrink: 0;
|
|
208
215
|
}
|
|
209
216
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
/* 播放三角:用 border 绘制,视觉居中略微右偏 */
|
|
218
|
+
.play-triangle {
|
|
219
|
+
width: 0;
|
|
220
|
+
height: 0;
|
|
221
|
+
border-style: solid;
|
|
222
|
+
border-width: 6px 0 6px 10px;
|
|
223
|
+
border-color: transparent transparent transparent #fff;
|
|
224
|
+
margin-left: 3px;
|
|
225
|
+
flex-shrink: 0;
|
|
215
226
|
}
|
|
216
227
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
border-bottom: 6px solid transparent;
|
|
224
|
-
border-left: 10px solid white;
|
|
228
|
+
/* 暂停符号:两条独立竖杠,用 margin 控制间距(小程序 gap 兼容性差) */
|
|
229
|
+
.pause-icon {
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
justify-content: center;
|
|
233
|
+
flex-shrink: 0;
|
|
225
234
|
}
|
|
226
235
|
|
|
227
|
-
.
|
|
228
|
-
.mini-icon.playing::after {
|
|
229
|
-
content: '';
|
|
230
|
-
position: absolute;
|
|
236
|
+
.pause-bar {
|
|
231
237
|
width: 3px;
|
|
232
238
|
height: 12px;
|
|
233
|
-
background:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
.mini-icon.playing::before {
|
|
237
|
-
left: 3px;
|
|
239
|
+
background-color: #fff;
|
|
240
|
+
border-radius: 1px;
|
|
238
241
|
}
|
|
239
242
|
|
|
240
|
-
.
|
|
241
|
-
left:
|
|
243
|
+
.pause-bar + .pause-bar {
|
|
244
|
+
margin-left: 3px;
|
|
242
245
|
}
|
|
243
246
|
|
|
244
247
|
.mini-progress {
|
|
@@ -405,6 +405,8 @@ async function select({ item }: { item: any }) {
|
|
|
405
405
|
msg: `确定${item.title}操作吗?`,
|
|
406
406
|
title: '提示',
|
|
407
407
|
success: () => {
|
|
408
|
+
// 消费完立即清空,避免 messageOptions 残留(与 del() 的处理保持一致)
|
|
409
|
+
message.close()
|
|
408
410
|
if (item.actionType === 'ractions') {
|
|
409
411
|
raction(item)
|
|
410
412
|
}
|
|
@@ -13,6 +13,8 @@ const props = defineProps({
|
|
|
13
13
|
type: { type: String, default: 'date' },
|
|
14
14
|
min: String,
|
|
15
15
|
max: String,
|
|
16
|
+
// 时间选择是否到秒(form-control 里 time 字段会传 use-second,之前组件没声明,属性被静默丢弃)
|
|
17
|
+
useSecond: { type: Boolean, default: false },
|
|
16
18
|
readonly: { type: Boolean, default: false },
|
|
17
19
|
})
|
|
18
20
|
|
|
@@ -27,10 +29,27 @@ interface SelectOption {
|
|
|
27
29
|
}
|
|
28
30
|
const open = ref(false)
|
|
29
31
|
const currentValue = ref<any>(props.modelValue)
|
|
32
|
+
// 传给 wd-calendar 的值:该组件只认 13 位时间戳,而表单里存的是 'YYYY-MM-DD HH:mm:ss' 之类的字符串
|
|
33
|
+
const calendarValue = ref<number | null>(null)
|
|
30
34
|
function clear() {
|
|
31
35
|
currentValue.value = ''
|
|
32
36
|
}
|
|
33
37
|
|
|
38
|
+
/** 字符串统一按 ISO 解析(iOS 对 'YYYY-MM-DD HH:mm:ss' 解析不稳定),时间戳/Date 直接交给 dayjs */
|
|
39
|
+
function toDayjs(value: any) {
|
|
40
|
+
return typeof value === 'string' ? dayjs(value.trim().replace(' ', 'T')) : dayjs(value)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 表单值(字符串/时间戳)→ 13 位时间戳,无法解析时返回 null */
|
|
44
|
+
function toTimestamp(value: any): number | null {
|
|
45
|
+
if (value === undefined || value === null || value === '') return null
|
|
46
|
+
if (typeof value === 'number') return value
|
|
47
|
+
const str = String(value).trim()
|
|
48
|
+
if (/^\d{10,13}$/.test(str)) return Number(str)
|
|
49
|
+
const date = toDayjs(str)
|
|
50
|
+
return date.isValid() ? date.valueOf() : null
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
watch(
|
|
35
54
|
() => props.modelValue,
|
|
36
55
|
val => {
|
|
@@ -39,10 +58,37 @@ watch(
|
|
|
39
58
|
)
|
|
40
59
|
|
|
41
60
|
watch(currentValue, val => {
|
|
42
|
-
|
|
61
|
+
if (val === '' || val === undefined || val === null) {
|
|
62
|
+
emit('update:modelValue', '')
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
const newVal = ['year', 'month'].includes(props.type) ? toDayjs(val).format('YYYY-MM') : val
|
|
43
66
|
emit('update:modelValue', newVal)
|
|
44
67
|
})
|
|
45
68
|
|
|
69
|
+
// datetime 类型下「选中某个日期」时使用的当日内时刻
|
|
70
|
+
const defaultTime = ref<string | undefined>(undefined)
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 打开弹窗时同步面板值:
|
|
74
|
+
* - 表单已有值:转成时间戳,让面板定位并高亮到该日期
|
|
75
|
+
* - 表单为空:默认选中「现在」(datetime 会带上当前时分秒),直接点确定即可用当前时间
|
|
76
|
+
* 这里只设置面板值、不写回表单,用户取消关闭不会污染空字段
|
|
77
|
+
*/
|
|
78
|
+
watch(open, val => {
|
|
79
|
+
if (!val) return
|
|
80
|
+
const now = dayjs()
|
|
81
|
+
// datetime 选中日期时若不给默认时刻会落到 00:00:00,这里统一用当前时分秒
|
|
82
|
+
defaultTime.value = props.type === 'datetime' ? now.format('HH:mm:ss') : undefined
|
|
83
|
+
calendarValue.value = toTimestamp(currentValue.value) ?? now.valueOf()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
/** 日历确认后才写回表单,避免「打开即赋值」 */
|
|
87
|
+
function handleCalendarConfirm({ value }: { value: number | number[] | null }) {
|
|
88
|
+
if (value === undefined || value === null) return
|
|
89
|
+
currentValue.value = value
|
|
90
|
+
}
|
|
91
|
+
|
|
46
92
|
const labelText = computed(() => {
|
|
47
93
|
const formatMap: {
|
|
48
94
|
date: string
|
|
@@ -50,12 +96,14 @@ const labelText = computed(() => {
|
|
|
50
96
|
[key: string]: string // 索引签名:允许任意字符串作为键
|
|
51
97
|
} = {
|
|
52
98
|
date: 'YYYY-MM-DD',
|
|
53
|
-
|
|
99
|
+
// 回显到秒,避免选完时间看不到秒
|
|
100
|
+
datetime: 'YYYY-MM-DD HH:mm:ss',
|
|
54
101
|
year: 'YYYY',
|
|
55
102
|
}
|
|
56
103
|
|
|
57
104
|
if (['date', 'datetime', 'year'].includes(props.type)) {
|
|
58
|
-
|
|
105
|
+
const date = currentValue.value ? toDayjs(currentValue.value) : null
|
|
106
|
+
return date && date.isValid() ? date.format(formatMap[props.type] as string) : ''
|
|
59
107
|
} else {
|
|
60
108
|
return currentValue.value || ''
|
|
61
109
|
}
|
|
@@ -72,13 +120,15 @@ console.log('labelText', props)
|
|
|
72
120
|
|
|
73
121
|
<wd-calendar
|
|
74
122
|
v-if="['date', 'datetime', 'month'].includes(type)"
|
|
75
|
-
v-model="
|
|
123
|
+
v-model="calendarValue"
|
|
76
124
|
v-model:visible="open"
|
|
77
125
|
label-key="label"
|
|
78
126
|
value-key="value"
|
|
79
127
|
class="custom-date-picker"
|
|
80
128
|
:type="type as any"
|
|
81
129
|
:min-date="props.min === '$$current' ? dayjs().startOf('day').valueOf() : undefined"
|
|
130
|
+
:default-time="defaultTime"
|
|
131
|
+
@confirm="handleCalendarConfirm"
|
|
82
132
|
/>
|
|
83
133
|
<wd-datetime-picker
|
|
84
134
|
v-else
|
|
@@ -88,6 +138,7 @@ console.log('labelText', props)
|
|
|
88
138
|
value-key="value"
|
|
89
139
|
class="custom-date-picker"
|
|
90
140
|
:type="type as any"
|
|
141
|
+
:use-second="useSecond"
|
|
91
142
|
/>
|
|
92
143
|
</template>
|
|
93
144
|
|
|
@@ -619,6 +619,20 @@ function handleFileChange(e: any, item: Fields) {
|
|
|
619
619
|
model.value[item.sourceId] = e.fileList
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
+
/**
|
|
623
|
+
* 时间字段的值是 'HH:mm' / 'HH:mm:ss' 字符串,dayjs 直接解析会得到 Invalid Date,
|
|
624
|
+
* 这里补一个日期前缀(用 ISO 格式,iOS 也能稳定解析)
|
|
625
|
+
*/
|
|
626
|
+
function formatTimeValue(value: any): string {
|
|
627
|
+
if (!value) return ''
|
|
628
|
+
if (typeof value === 'number') return dayjs(value).format('HH:mm:ss')
|
|
629
|
+
const str = String(value).trim()
|
|
630
|
+
if (!str.includes(':')) return str
|
|
631
|
+
const time = str.length === 5 ? `${str}:00` : str
|
|
632
|
+
const parsed = dayjs(`2000-01-01T${time}`)
|
|
633
|
+
return parsed.isValid() ? parsed.format('HH:mm:ss') : str
|
|
634
|
+
}
|
|
635
|
+
|
|
622
636
|
function submit() {
|
|
623
637
|
return new Promise((resolve, reject) => {
|
|
624
638
|
form.value
|
|
@@ -662,7 +676,7 @@ function submit() {
|
|
|
662
676
|
} else if (ControlTypeSupportor.getControlType(item) === 'datetime') {
|
|
663
677
|
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY-MM-DD HH:mm:ss') : ''
|
|
664
678
|
} else if (ControlTypeSupportor.getControlType(item) === 'time') {
|
|
665
|
-
data[key] =
|
|
679
|
+
data[key] = formatTimeValue(model.value[key])
|
|
666
680
|
} else if (ControlTypeSupportor.getControlType(item) === 'date-YY') {
|
|
667
681
|
data[key] = model.value[key] ? dayjs(model.value[key]).format('YYYY') : ''
|
|
668
682
|
} else if (ControlTypeSupportor.getControlType(item) === 'date-M1') {
|
|
@@ -9,7 +9,8 @@ defineOptions({
|
|
|
9
9
|
name: 'GlobalMessage',
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const messageStore = useGlobalMessage()
|
|
13
|
+
const { messageOptions } = storeToRefs(messageStore)
|
|
13
14
|
|
|
14
15
|
const dialog = useDialog()
|
|
15
16
|
const currentPath = getCurrentPath()
|
|
@@ -24,23 +25,26 @@ nextTick(() => {
|
|
|
24
25
|
|
|
25
26
|
watch(() => messageOptions.value, (newVal) => {
|
|
26
27
|
if (newVal) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
// 抢占消费权:页面上若存在多个 GlobalMessage 实例(tabbar 布局一份 + wui-list 内一份),
|
|
29
|
+
// 只有第一个能取到 option,其余拿到 null 直接跳过,避免弹窗重复弹出、success 重复执行。
|
|
30
|
+
const claimed = messageStore.claim(currentPath)
|
|
31
|
+
if (!claimed)
|
|
32
|
+
return
|
|
33
|
+
const option = CommonUtil.deepClone(claimed)
|
|
34
|
+
const method = option.type === 'confirm'
|
|
35
|
+
? 'confirm'
|
|
36
|
+
: option.type === 'prompt'
|
|
37
|
+
? 'prompt'
|
|
38
|
+
: 'alert'
|
|
39
|
+
dialog[method](option).then((res) => {
|
|
40
|
+
if (CommonUtil.isFunction(option.success)) {
|
|
41
|
+
option.success(res)
|
|
42
|
+
}
|
|
43
|
+
}).catch((err) => {
|
|
44
|
+
if (CommonUtil.isFunction(option.fail)) {
|
|
45
|
+
option.fail(err)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
46
50
|
dialog.close()
|
|
@@ -102,9 +102,14 @@ function goDetail(item: Columns) {
|
|
|
102
102
|
})
|
|
103
103
|
.join('&')
|
|
104
104
|
const sep = params ? (fieldJump.mobilePath.includes('?') ? '&' : '?') : ''
|
|
105
|
-
//
|
|
105
|
+
// 只对 mobilePath 中未编码的非 ASCII 做编码,避免 encodeURI 二次编码已编码的 % 导致 App 端乱码
|
|
106
|
+
let safePath = String(fieldJump.mobilePath).replace(/[^\x00-\x7F]+/g, s => encodeURIComponent(s))
|
|
107
|
+
// 绝对路径补前导斜杠(相对路径不受影响)
|
|
108
|
+
if (!safePath.startsWith('/') && !safePath.startsWith('./') && !safePath.startsWith('../')) {
|
|
109
|
+
safePath = `/${safePath}`
|
|
110
|
+
}
|
|
106
111
|
uni.navigateTo({
|
|
107
|
-
url:
|
|
112
|
+
url: `${safePath}${sep}${params}`,
|
|
108
113
|
})
|
|
109
114
|
return
|
|
110
115
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { defineOptions, ref } from 'vue'
|
|
2
|
+
import { defineOptions, onMounted, onUnmounted, ref } from 'vue'
|
|
3
3
|
import { onLoad } from '@dcloudio/uni-app'
|
|
4
4
|
import { detailPageConfig, detailPageData } from '../../api/page'
|
|
5
5
|
import type { Entities, Groups, dtmplConfig } from '../../type'
|
|
6
6
|
import CardBotomButtons from '../card-botom-buttons/card-botom-buttons.vue'
|
|
7
7
|
import foldCard from '../fold-card/fold-card.vue'
|
|
8
8
|
import LabelValue from '../label-value/label-value.vue'
|
|
9
|
+
import { generateHighResolutionID } from '../../utils/index'
|
|
9
10
|
|
|
10
11
|
defineOptions({
|
|
11
12
|
name: 'WuiDetailsPage',
|
|
@@ -56,6 +57,10 @@ const groups = ref<Groups>({
|
|
|
56
57
|
displayConfig: [],
|
|
57
58
|
})
|
|
58
59
|
const loading = ref(false)
|
|
60
|
+
// 全局事件名:本页新增/编辑关联记录保存后,用于接收刷新信号
|
|
61
|
+
const addEvent = generateHighResolutionID()
|
|
62
|
+
// CardBotomButtons 需要 zpaging 对象(删除/复制后刷新),详情页用自身数据重载模拟
|
|
63
|
+
const detailZpaging = { reload: () => getDetailData() }
|
|
59
64
|
// 折叠面板
|
|
60
65
|
const collapses = ref()
|
|
61
66
|
/**
|
|
@@ -144,6 +149,14 @@ async function getDetailData() {
|
|
|
144
149
|
console.log(error)
|
|
145
150
|
}
|
|
146
151
|
}
|
|
152
|
+
|
|
153
|
+
onMounted(() => {
|
|
154
|
+
// 详情页内的关联记录新增/编辑保存后,重新拉取详情数据
|
|
155
|
+
uni.$on(addEvent, () => getDetailData())
|
|
156
|
+
})
|
|
157
|
+
onUnmounted(() => {
|
|
158
|
+
uni.$off(addEvent)
|
|
159
|
+
})
|
|
147
160
|
</script>
|
|
148
161
|
|
|
149
162
|
<template>
|
|
@@ -190,6 +203,8 @@ async function getDetailData() {
|
|
|
190
203
|
:item="groups"
|
|
191
204
|
:code="field.code"
|
|
192
205
|
:data="data"
|
|
206
|
+
:add-event="addEvent"
|
|
207
|
+
:zpaging="detailZpaging"
|
|
193
208
|
:detail-button-handle="props.detailButtonHandle"
|
|
194
209
|
/>
|
|
195
210
|
</template>
|
|
@@ -91,17 +91,31 @@ function isActionDisabled(item: rowActions): boolean {
|
|
|
91
91
|
return false
|
|
92
92
|
}
|
|
93
93
|
console.log(pageActions.value, 'pageActions.value')
|
|
94
|
+
/**
|
|
95
|
+
* 兼容调用方漏传参数的情况:URL 拼接会把 undefined/null 变成字面量字符串,
|
|
96
|
+
* 原样赋值会让 uni.$emit('undefined') 发到一个不存在的事件名上,上一页永远收不到刷新信号。
|
|
97
|
+
*/
|
|
98
|
+
function normalizeParam(value?: any): string {
|
|
99
|
+
if (value === undefined || value === null || value === 'undefined' || value === 'null') return ''
|
|
100
|
+
return String(value)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 从各类错误对象(接口错误/Error/小程序 errMsg)里提取可展示的提示文案 */
|
|
104
|
+
function errorMessage(error: any, fallback = '操作失败'): string {
|
|
105
|
+
return error?.data?.message || error?.data?.msg || error?.errMsg || error?.message || fallback
|
|
106
|
+
}
|
|
107
|
+
|
|
94
108
|
onLoad((option: any) => {
|
|
95
109
|
sourceId.value = option.sourceId
|
|
96
|
-
mainCode.value = option.mainCode
|
|
97
|
-
id.value = option.id
|
|
110
|
+
mainCode.value = normalizeParam(option.mainCode)
|
|
111
|
+
id.value = normalizeParam(option.id)
|
|
98
112
|
pageTitle.value = option.title
|
|
99
|
-
addEvent.value = option.addEvent
|
|
100
|
-
editEvent.value = option.editEvent
|
|
101
|
-
pageType.value = option.pageType
|
|
102
|
-
rowAddEvent.value = option.rowAddEvent
|
|
103
|
-
sendRowAddEvent.value = option.sendRowAddEvent
|
|
104
|
-
copyEvent.value = option.copyEvent
|
|
113
|
+
addEvent.value = normalizeParam(option.addEvent)
|
|
114
|
+
editEvent.value = normalizeParam(option.editEvent)
|
|
115
|
+
pageType.value = normalizeParam(option.pageType)
|
|
116
|
+
rowAddEvent.value = normalizeParam(option.rowAddEvent)
|
|
117
|
+
sendRowAddEvent.value = normalizeParam(option.sendRowAddEvent)
|
|
118
|
+
copyEvent.value = normalizeParam(option.copyEvent)
|
|
105
119
|
// 复制场景:仅当 URL 带 copyEvent 标识(即"复制新增")才读取预填数据;
|
|
106
120
|
// 普通新增不带该标识,绝不读取存储,避免复制残留数据污染普通新增
|
|
107
121
|
if (copyEvent.value) {
|
|
@@ -259,8 +273,10 @@ async function getEnums() {
|
|
|
259
273
|
// 行添加保存
|
|
260
274
|
async function rowAddSave(all: any) {
|
|
261
275
|
console.log('行数据', all)
|
|
262
|
-
|
|
276
|
+
// 先发送数据再返回:返回会触发本页 onUnmounted 里的 uni.$off(rowAddEvent),
|
|
277
|
+
// 放在 back() 之后发送有概率被父页面的监听错过
|
|
263
278
|
uni.$emit(rowAddEvent.value, all)
|
|
279
|
+
router.back()
|
|
264
280
|
}
|
|
265
281
|
|
|
266
282
|
// 保存数据并返回保存后的实体编码;行添加场景会在内部直接处理跳转
|
|
@@ -268,7 +284,9 @@ async function saveData(): Promise<{ entityCode: string; data: Record<string, an
|
|
|
268
284
|
// 判断是否为树添加
|
|
269
285
|
if (pageType.value === '树' && !tree.value.value) {
|
|
270
286
|
globalToast.warning('请选择分组')
|
|
271
|
-
|
|
287
|
+
const err: any = new Error('请选择分组')
|
|
288
|
+
err.handled = true // 已提示过,save() 的 catch 不再重复弹提示
|
|
289
|
+
throw err
|
|
272
290
|
}
|
|
273
291
|
|
|
274
292
|
const formArray: any[] = []
|
|
@@ -371,27 +389,38 @@ async function saveData(): Promise<{ entityCode: string; data: Record<string, an
|
|
|
371
389
|
return { entityCode: saveRes.entityCode, data: newAll }
|
|
372
390
|
}
|
|
373
391
|
|
|
392
|
+
/**
|
|
393
|
+
* 统一广播刷新信号,通知上一页/弹窗重新取数:
|
|
394
|
+
* - addEvent / editEvent:调用方(列表、树页面、选人组件)注册的事件
|
|
395
|
+
* - selectPopup:refresh:选择弹窗列表
|
|
396
|
+
*/
|
|
397
|
+
function emitRefresh(entityCode = '', data: Record<string, any> = {}) {
|
|
398
|
+
if (addEvent.value) uni.$emit(addEvent.value, { entityCode, data })
|
|
399
|
+
if (editEvent.value) uni.$emit(editEvent.value, entityCode)
|
|
400
|
+
uni.$emit('selectPopup:refresh', sourceId.value)
|
|
401
|
+
}
|
|
402
|
+
|
|
374
403
|
// 保存
|
|
375
404
|
async function save() {
|
|
376
405
|
try {
|
|
377
406
|
const { entityCode, data } = await saveData()
|
|
378
407
|
// 行添加场景已在 saveData 内完成跳转
|
|
379
408
|
if (rowAddEvent.value) return
|
|
380
|
-
//
|
|
381
|
-
|
|
382
|
-
if (editEvent.value) uni.$emit(editEvent.value, entityCode)
|
|
383
|
-
|
|
384
|
-
// ★ 通知 wui-select-popup 刷新列表数据
|
|
385
|
-
uni.$emit('selectPopup:refresh', sourceId.value)
|
|
409
|
+
// 发送事件,通知上一页/弹窗刷新
|
|
410
|
+
emitRefresh(entityCode, data)
|
|
386
411
|
|
|
387
412
|
// 复制场景:保存成功后清除本次复制数据(按 copyEvent key),避免残留
|
|
388
413
|
if (copyEvent.value) uni.removeStorageSync(copyEvent.value)
|
|
389
414
|
|
|
390
415
|
subLoading.value = false
|
|
391
416
|
router.back()
|
|
392
|
-
} catch (error) {
|
|
417
|
+
} catch (error: any) {
|
|
393
418
|
subLoading.value = false
|
|
394
419
|
console.log('error:', error)
|
|
420
|
+
// 之前只打日志:保存失败(校验不通过、401、网络异常等)界面上完全没有反馈
|
|
421
|
+
if (!error?.handled) {
|
|
422
|
+
globalToast.error(errorMessage(error, '保存失败'))
|
|
423
|
+
}
|
|
395
424
|
}
|
|
396
425
|
}
|
|
397
426
|
|
|
@@ -399,8 +428,13 @@ async function save() {
|
|
|
399
428
|
const actionItem = ref<Groups>()
|
|
400
429
|
const actionItemShow = ref(false)
|
|
401
430
|
const actionCode = ref('')
|
|
402
|
-
// ActionPopup 成功后的刷新处理(编辑页无 zpaging
|
|
403
|
-
const actionZpaging = {
|
|
431
|
+
// ActionPopup 成功后的刷新处理(编辑页无 zpaging:先广播刷新信号,再返回上一页)
|
|
432
|
+
const actionZpaging = {
|
|
433
|
+
reload: () => {
|
|
434
|
+
emitRefresh(id.value)
|
|
435
|
+
router.back()
|
|
436
|
+
},
|
|
437
|
+
}
|
|
404
438
|
|
|
405
439
|
// 执行底部动态操作按钮:直接走 action 接口(不提交表单)
|
|
406
440
|
async function executeAction(subitem: rowActions) {
|
|
@@ -456,12 +490,13 @@ async function doAction(subitem: rowActions) {
|
|
|
456
490
|
await actionDataSave(subitem.id, actionCode.value, {})
|
|
457
491
|
subLoading.value = false
|
|
458
492
|
globalToast.success({ msg: '操作成功!' })
|
|
459
|
-
//
|
|
460
|
-
|
|
493
|
+
// 通知列表/弹窗刷新后返回:只发 selectPopup:refresh 时列表页收不到
|
|
494
|
+
emitRefresh(id.value)
|
|
461
495
|
router.back()
|
|
462
496
|
} catch (error: any) {
|
|
463
497
|
subLoading.value = false
|
|
464
|
-
|
|
498
|
+
// 传错误对象当 ToastOptions 是显示不出文案的,这里取出 message
|
|
499
|
+
globalToast.error(errorMessage(error))
|
|
465
500
|
}
|
|
466
501
|
}
|
|
467
502
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed, defineOptions, onMounted, onUnmounted, ref } from 'vue'
|
|
3
|
-
import { onLoad } from '@dcloudio/uni-app'
|
|
3
|
+
import { onHide, onLoad, onShow } from '@dcloudio/uni-app'
|
|
4
4
|
import { actionDataSave, deleteData, listData, pageConfig, pageKey } from '../../api/page'
|
|
5
5
|
import foldCard2 from '../fold-card2/fold-card2.vue'
|
|
6
6
|
import type { Config, EditButtonConfig, Entities, rowActions } from '../../type'
|
|
@@ -15,6 +15,7 @@ import tabSearch from '../tab-search/tab-search.vue'
|
|
|
15
15
|
import { useEnums } from '../../composables/useEnumes'
|
|
16
16
|
import { useGlobalToast } from '../../composables/useGlobalToast'
|
|
17
17
|
import { useGlobalMessage } from '../../composables/useGlobalMessage'
|
|
18
|
+
import GlobalMessage from '../global-message/global-message.vue'
|
|
18
19
|
|
|
19
20
|
defineOptions({
|
|
20
21
|
name: 'WuiList',
|
|
@@ -120,6 +121,10 @@ const props = withDefaults(
|
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
const Zpaging = ref<any>(null)
|
|
124
|
+
/** 是否已经历过首次显示:首次显示由 z-paging 自己加载,避免重复请求 */
|
|
125
|
+
const hasShown = ref(false)
|
|
126
|
+
/** 本次隐藏期间是否已通过刷新事件取过数:避免返回时 onShow 再重复请求一次 */
|
|
127
|
+
let refreshedWhileHidden = false
|
|
123
128
|
const config = ref<Config>({
|
|
124
129
|
buttons: [],
|
|
125
130
|
columns: [],
|
|
@@ -375,6 +380,8 @@ async function batchAction(item: rowActions) {
|
|
|
375
380
|
msg: `确定对选中的 ${codes.length} 条记录执行「${item.title}」操作吗?`,
|
|
376
381
|
title: '提示',
|
|
377
382
|
success: async () => {
|
|
383
|
+
// 消费完立即清空,避免 messageOptions 残留
|
|
384
|
+
message.close()
|
|
378
385
|
try {
|
|
379
386
|
await actionDataSave(item.id, codes.join(','), {})
|
|
380
387
|
toast.success({ msg: '操作成功!' })
|
|
@@ -427,9 +434,28 @@ onMounted(async () => {
|
|
|
427
434
|
console.log('mounted')
|
|
428
435
|
// 监听添加成功的事件
|
|
429
436
|
uni.$on(addEvent, async () => {
|
|
437
|
+
refreshedWhileHidden = true
|
|
430
438
|
Zpaging.value.reload()
|
|
431
439
|
})
|
|
432
440
|
})
|
|
441
|
+
// 页面隐藏时复位标记,保证标记只对"紧接着的那一次显示"生效
|
|
442
|
+
onHide(() => {
|
|
443
|
+
refreshedWhileHidden = false
|
|
444
|
+
})
|
|
445
|
+
// 页面重新显示时刷新列表:不再只依赖上一页的刷新事件
|
|
446
|
+
// (编辑页未保存/保存接口失败/事件名不匹配时,事件链会失效,这里做兜底)
|
|
447
|
+
onShow(() => {
|
|
448
|
+
if (!hasShown.value) {
|
|
449
|
+
hasShown.value = true
|
|
450
|
+
return
|
|
451
|
+
}
|
|
452
|
+
// 隐藏期间已经收到过刷新事件的话,这次显示就不用再请求一遍
|
|
453
|
+
if (refreshedWhileHidden) {
|
|
454
|
+
refreshedWhileHidden = false
|
|
455
|
+
return
|
|
456
|
+
}
|
|
457
|
+
Zpaging.value?.reload()
|
|
458
|
+
})
|
|
433
459
|
// 在组件卸载时解绑全局事件
|
|
434
460
|
onUnmounted(() => {
|
|
435
461
|
console.log(`${pageTitle.value}页面卸载`)
|
|
@@ -537,7 +563,6 @@ function tabSearchClick(data: any) {
|
|
|
537
563
|
:show-loading-more-when-reload="true"
|
|
538
564
|
@query="queryList"
|
|
539
565
|
>
|
|
540
|
-
<GlobalMessage />
|
|
541
566
|
<template #top>
|
|
542
567
|
<slot name="top" />
|
|
543
568
|
<Search
|
|
@@ -721,6 +746,11 @@ function tabSearchClick(data: any) {
|
|
|
721
746
|
<slot name="bottom" />
|
|
722
747
|
</template>
|
|
723
748
|
</z-paging>
|
|
749
|
+
|
|
750
|
+
<!-- 非 tabBar 页面没有 wui-tabbar 挂载 global-message,
|
|
751
|
+
列表页自包含挂载一份(必须在 z-paging 外层,避免滚动容器裁剪弹层),
|
|
752
|
+
确保卡片底部操作按钮的 confirm/alert 弹窗可正常弹出。 -->
|
|
753
|
+
<GlobalMessage />
|
|
724
754
|
</template>
|
|
725
755
|
|
|
726
756
|
<style scoped>
|
|
@@ -121,7 +121,7 @@ async function fetchUserInfo() {
|
|
|
121
121
|
const sourceId = 'x4u6aJ6IQQ'
|
|
122
122
|
if (user.id) {
|
|
123
123
|
const entityRes = await req({
|
|
124
|
-
url: `/v3/mstruc/data?sourceId=${sourceId}&depth=1&pageNo=1&pageSize=1&
|
|
124
|
+
url: `/v3/mstruc/data?sourceId=${sourceId}&depth=1&pageNo=1&pageSize=1&c_唯一编码_equals=${user.id}&c_标记删除_equals=否`,
|
|
125
125
|
method: 'GET',
|
|
126
126
|
})
|
|
127
127
|
const list = entityRes?.entities || entityRes?.data?.entities || []
|
|
@@ -227,12 +227,10 @@ async function clearCache() {
|
|
|
227
227
|
if (res.status === 'success') {
|
|
228
228
|
toast.success({ msg: '清除成功!' })
|
|
229
229
|
uni.setStorageSync('userInfo', res.user)
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
230
|
+
} else {
|
|
232
231
|
toast.error({ msg: res.message || res.msg || '清除失败,请重试' })
|
|
233
232
|
}
|
|
234
|
-
}
|
|
235
|
-
catch (error: any) {
|
|
233
|
+
} catch (error: any) {
|
|
236
234
|
console.error('清除缓存失败:', error)
|
|
237
235
|
toast.error({ msg: error?.data?.message || '清除失败,请检查登录状态' })
|
|
238
236
|
}
|
|
@@ -264,7 +262,6 @@ function saveSensorConfig() {
|
|
|
264
262
|
toast.success({ msg: '传感器配置保存成功' })
|
|
265
263
|
showSensorConfig.value = false
|
|
266
264
|
}
|
|
267
|
-
|
|
268
265
|
</script>
|
|
269
266
|
|
|
270
267
|
<template>
|
|
@@ -12,6 +12,19 @@ interface GlobalMessage {
|
|
|
12
12
|
currentPage: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 消费锁。
|
|
17
|
+
*
|
|
18
|
+
* 页面上可能同时存在多个 GlobalMessage 实例(例如 tabbar 布局挂一份,
|
|
19
|
+
* wui-list 内部又自包含挂一份)。这些实例都 watch 同一个 store 的 messageOptions,
|
|
20
|
+
* 一次 confirm 会被多个实例同时消费 —— 弹窗被反复弹出,success 回调执行多次,
|
|
21
|
+
* 表现为「列表项操作弹窗触发两次」「接口重复提交」。
|
|
22
|
+
*
|
|
23
|
+
* 多个实例的 watch 回调会在同一个 tick 内同步依次执行,
|
|
24
|
+
* 这里用「先到先得」的消费锁保证同一次消息只被真正消费一次。
|
|
25
|
+
*/
|
|
26
|
+
let consumedTicket: symbol | null = null
|
|
27
|
+
|
|
15
28
|
export const useGlobalMessage = defineStore('global-message', {
|
|
16
29
|
state: (): GlobalMessage => ({
|
|
17
30
|
messageOptions: null,
|
|
@@ -20,6 +33,8 @@ export const useGlobalMessage = defineStore('global-message', {
|
|
|
20
33
|
actions: {
|
|
21
34
|
show(option: GlobalMessageOptions | string) {
|
|
22
35
|
this.currentPage = getCurrentPath()
|
|
36
|
+
// 新消息入队,释放上一次的消费锁
|
|
37
|
+
consumedTicket = null
|
|
23
38
|
this.messageOptions = {
|
|
24
39
|
...(CommonUtil.isString(option) ? { title: option } : option),
|
|
25
40
|
cancelButtonProps: {
|
|
@@ -45,7 +60,24 @@ export const useGlobalMessage = defineStore('global-message', {
|
|
|
45
60
|
messageOptions.showCancelButton = true
|
|
46
61
|
this.show(messageOptions)
|
|
47
62
|
},
|
|
63
|
+
/**
|
|
64
|
+
* 尝试消费当前消息。
|
|
65
|
+
*
|
|
66
|
+
* 同一条消息只允许被一个 GlobalMessage 实例取走,重复实例拿到 null 后直接跳过,
|
|
67
|
+
* 从而避免弹窗被弹出多次、success 回调被执行多次。
|
|
68
|
+
*
|
|
69
|
+
* currentPath 不匹配的实例不会占用锁,避免消息被错误实例吞掉后无人弹出。
|
|
70
|
+
*/
|
|
71
|
+
claim(currentPath: string): GlobalMessageOptions | null {
|
|
72
|
+
if (!this.messageOptions || consumedTicket !== null)
|
|
73
|
+
return null
|
|
74
|
+
if (this.currentPage !== currentPath)
|
|
75
|
+
return null
|
|
76
|
+
consumedTicket = Symbol('global-message-consumed')
|
|
77
|
+
return this.messageOptions
|
|
78
|
+
},
|
|
48
79
|
close() {
|
|
80
|
+
consumedTicket = null
|
|
49
81
|
this.messageOptions = null
|
|
50
82
|
this.currentPage = ''
|
|
51
83
|
},
|