wui-components-v2 1.2.41 → 1.2.43

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.
@@ -163,7 +163,7 @@ onMounted(() => {
163
163
  >
164
164
  <view
165
165
  class="menu-icon-wrapper flex items-center justify-center"
166
- :style="{ background: subItem.color }"
166
+ :style="{ background: subItem.themeColor }"
167
167
  >
168
168
  <text class="menu-icon !text-xl iconfont" :class="[subItem.appIcon || 'i-carbon:grid']" />
169
169
  <view class="icon-shine" />
@@ -193,12 +193,7 @@ onMounted(() => {
193
193
  </template>
194
194
 
195
195
  <template v-else>
196
- <slot
197
- name="tile"
198
- :items="tileItems"
199
- :goto="handleItemClick"
200
- :t="languageStore.t"
201
- />
196
+ <slot name="tile" :items="tileItems" :goto="handleItemClick" :t="languageStore.t" />
202
197
  </template>
203
198
  </view>
204
199
 
@@ -4,9 +4,11 @@ import { useDialog } from '@wot-ui/ui'
4
4
  import { useUser } from '../../composables/useUser'
5
5
  import { generateGradientColor } from '../../utils'
6
6
  import { useManualTheme } from '../../composables/useManualTheme'
7
- import scan from '../scan-input/scan-input.vue'
8
7
  import { getUserConfig } from '../../api/login'
9
8
  import { useGlobalToast } from '../../composables/useGlobalToast'
9
+ import { req } from '../../api/index'
10
+ import WuiUpdateComponent from '../wui-update-component/wui-update-component.vue'
11
+ import { onShow } from '@dcloudio/uni-app'
10
12
 
11
13
  defineOptions({
12
14
  name: 'WuiUser',
@@ -24,6 +26,56 @@ const props = defineProps({
24
26
  type: Boolean,
25
27
  default: true,
26
28
  },
29
+ // 租户名称
30
+ tenantName: {
31
+ type: String,
32
+ default: '',
33
+ },
34
+ // 传感器编号(不传则从本地缓存读取 sensorCode)
35
+ sensorCode: {
36
+ type: String,
37
+ default: '',
38
+ },
39
+ // 是否显示"传感器绑定"
40
+ showSensorBind: {
41
+ type: Boolean,
42
+ default: true,
43
+ },
44
+ // 绑定传感器页面路径
45
+ bindPath: {
46
+ type: String,
47
+ default: '/pages/binding-sensor/index',
48
+ },
49
+ // 是否显示"检查更新"
50
+ showUpdate: {
51
+ type: Boolean,
52
+ default: false,
53
+ },
54
+ // 是否显示"修改传感器配置"
55
+ showSensorConfig: {
56
+ type: Boolean,
57
+ default: true,
58
+ },
59
+ // 是否云音(听音)模式:控制"修改传感器配置"的听音功能
60
+ isYunyin: {
61
+ type: Boolean,
62
+ default: false,
63
+ },
64
+ // 是否显示传感器状态卡片
65
+ showSensorStatus: {
66
+ type: Boolean,
67
+ default: true,
68
+ },
69
+ // 传感器在线状态查询:接收传感器编号,返回 Promise<boolean 或 1|0>
70
+ sensorOnlineApi: {
71
+ type: Function,
72
+ default: null,
73
+ },
74
+ // 更新组件配置:{ baseUrl, hydrocarbonProgramToken, sourceId, appId }
75
+ updateConfig: {
76
+ type: Object,
77
+ default: () => ({}),
78
+ },
27
79
  })
28
80
 
29
81
  const { currentThemeColor, isDark } = useManualTheme()
@@ -39,13 +91,101 @@ const cellGroupStyle = computed(() => ({
39
91
  backgroundColor: isDark.value ? '#111111' : 'transparent',
40
92
  borderRadius: isDark.value ? '10px' : '0',
41
93
  }))
42
- const user = useUser().getUserInfo()
43
94
  const dialog = useDialog()
44
95
  const toast = useGlobalToast()
96
+
97
+ // 从实体字段映射(fieldMap)中读取字段值,与参考模板中用户实体字段保持一致
98
+ function readUserField(fieldMap: Record<string, any>, key: string): string {
99
+ const val = fieldMap?.[key]
100
+ if (val === undefined || val === null) return ''
101
+ // 实体字段可能是 "编码@R@名称" 形式,取展示名称
102
+ return typeof val === 'string' && val.includes('@R@') ? val.split('@R@')[1] || val.split('@R@')[0] : String(val)
103
+ }
104
+
105
+ const storeUser = useUser().getUserInfo()
45
106
  const userInfo = ref({
46
- name: user.name,
47
- nickName: user.nickName,
107
+ name: storeUser.name,
108
+ nickName: storeUser.nickName,
109
+ tenantName: storeUser.tenantName ?? storeUser.tenant_name ?? '',
48
110
  })
111
+ // 租户名称:优先取外部传入的 prop,否则从用户信息中读取
112
+ const tenantName = computed(() => props.tenantName || userInfo.value.tenantName)
113
+
114
+ // 组件内部自行获取用户信息(含租户名称等实体字段),保持组件独立封装
115
+ async function fetchUserInfo() {
116
+ try {
117
+ const res = await getUserConfig()
118
+ if (res?.status !== 'success' || !res.user) return
119
+ const fieldMap = res.user.extInfo?.fieldMap || {}
120
+ userInfo.value = {
121
+ name: readUserField(fieldMap, '姓名') || res.user.name || userInfo.value.name,
122
+ nickName: readUserField(fieldMap, '账号') || res.user.nickName || userInfo.value.nickName,
123
+ tenantName:
124
+ readUserField(fieldMap, '维修厂') ||
125
+ (res.user.tenantName ?? res.user.tenant_name ?? userInfo.value.tenantName),
126
+ }
127
+ } catch (error) {
128
+ console.error('获取用户信息失败:', error)
129
+ }
130
+ }
131
+
132
+ // ==================== 传感器状态 ====================
133
+ const showVersion = ref(false) // 更新版本开关
134
+ const showSensorConfig = ref(false) // 传感器配置弹窗开关
135
+ const listenDuration = ref(2) // 单次听音时长,默认2秒
136
+ const sensor = ref(0) // 传感器在线状态 1:在线 0:离线
137
+ const sensorCode = ref(props.sensorCode || uni.getStorageSync('sensorCode') || '')
138
+
139
+ onShow(() => {
140
+ // 组件内部获取用户信息(租户名称等),保持独立
141
+ fetchUserInfo()
142
+ if (!props.sensorCode) {
143
+ sensorCode.value = uni.getStorageSync('sensorCode') || ''
144
+ }
145
+ if (props.showSensorStatus) {
146
+ getSensorInfo()
147
+ }
148
+ })
149
+
150
+ // 从返回结果中提取在线状态(兼容 1/0、true/false、嵌套 data 等结构)
151
+ function resolveSensorStatus(res: any): number {
152
+ const value = res && typeof res === 'object' ? (res.data ?? res) : res
153
+ if (typeof value === 'boolean') return value ? 1 : 0
154
+ return Number(value) ? 1 : 0
155
+ }
156
+
157
+ // 获取传感器在线信息
158
+ const getSensorInfo = async (cli?: string) => {
159
+ let code = sensorCode.value
160
+ let newCode = code ? code.slice(3) : ''
161
+ if (!newCode) return
162
+ if (cli) {
163
+ toast.show({ msg: '传感器状态更新中' })
164
+ }
165
+ try {
166
+ if (props.sensorOnlineApi) {
167
+ const res = await props.sensorOnlineApi({ sensorCode: newCode })
168
+ sensor.value = resolveSensorStatus(res)
169
+ } else {
170
+ const res = await req({
171
+ url: `/v3/mstruc/sensor/online`,
172
+ method: 'GET',
173
+ data: { sensorCode: newCode },
174
+ })
175
+ sensor.value = resolveSensorStatus(res)
176
+ }
177
+ if (cli) {
178
+ toast.success({ msg: '传感器状态更新成功' })
179
+ }
180
+ } catch (error) {
181
+ console.error('传感器状态查询失败:', error)
182
+ if (cli) {
183
+ toast.error({ msg: '传感器状态更新失败' })
184
+ }
185
+ }
186
+ }
187
+
188
+ // ==================== 功能入口 ====================
49
189
 
50
190
  // 退出登录
51
191
  function quit() {
@@ -77,6 +217,33 @@ async function clearCache() {
77
217
  uni.setStorageSync('userInfo', res.user)
78
218
  }
79
219
  }
220
+
221
+ // 传感器绑定
222
+ function bind() {
223
+ uni.navigateTo({
224
+ url: props.bindPath,
225
+ })
226
+ }
227
+
228
+ // 检查更新
229
+ function queryVersion() {
230
+ showVersion.value = true
231
+ }
232
+
233
+ // 打开传感器配置弹窗
234
+ function openSensorConfig() {
235
+ // 从本地读取已保存的听音时长,默认2秒
236
+ const savedDuration = uni.getStorageSync('listenDuration')
237
+ listenDuration.value = savedDuration ? Number(savedDuration) : 2
238
+ showSensorConfig.value = true
239
+ }
240
+
241
+ // 保存传感器配置
242
+ function saveSensorConfig() {
243
+ uni.setStorageSync('listenDuration', listenDuration.value)
244
+ toast.success({ msg: '传感器配置保存成功' })
245
+ showSensorConfig.value = false
246
+ }
80
247
  </script>
81
248
 
82
249
  <template>
@@ -104,7 +271,30 @@ async function clearCache() {
104
271
  />
105
272
  <view class="user-text">
106
273
  <view class="user-name">{{ userInfo.name }}</view>
107
- <view class="user-nickname">昵称:{{ userInfo.nickName }}</view>
274
+ <view class="user-nickname">账号:{{ userInfo.nickName }}</view>
275
+ </view>
276
+ </view>
277
+ </view>
278
+ </view>
279
+
280
+ <!-- 传感器状态卡片 -->
281
+ <view v-if="showSensorStatus" class="card-box">
282
+ <view class="card" :class="{ 'card-dark': isDark }">
283
+ <view class="item">
284
+ <text class="label">租户名称</text>
285
+ <text :class="{ 'text-dark': isDark }">{{ tenantName }}</text>
286
+ </view>
287
+ <view class="item">
288
+ <text class="label">传感器编号</text>
289
+ <text :class="{ 'text-dark': isDark }">{{ sensorCode }}</text>
290
+ </view>
291
+ <view class="item">
292
+ <text class="label">传感器状态</text>
293
+ <view class="sensor-status">
294
+ <text class="sensor-text" :style="{ color: sensor === 1 ? '#2eba8b' : 'red' }">
295
+ {{ sensor === 1 ? '在线' : '离线' }}
296
+ </text>
297
+ <wd-icon name="refresh" size="34rpx" @click="getSensorInfo('c')" />
108
298
  </view>
109
299
  </view>
110
300
  </view>
@@ -112,6 +302,33 @@ async function clearCache() {
112
302
 
113
303
  <view class="mx-[15px] rounded-2">
114
304
  <wd-cell-group :custom-style="cellGroupStyle">
305
+ <wd-cell
306
+ v-if="isYunyin"
307
+ title="传感器绑定"
308
+ icon="link"
309
+ :is-link="true"
310
+ :clickable="true"
311
+ :custom-style="cellStyle"
312
+ @click="bind"
313
+ />
314
+ <wd-cell
315
+ v-if="showUpdate"
316
+ title="检查更新"
317
+ icon="refresh"
318
+ :is-link="true"
319
+ :clickable="true"
320
+ :custom-style="cellStyle"
321
+ @click="queryVersion"
322
+ />
323
+ <wd-cell
324
+ v-if="showSensorConfig && isYunyin"
325
+ title="修改传感器配置"
326
+ icon="edit"
327
+ :is-link="true"
328
+ :clickable="true"
329
+ :custom-style="cellStyle"
330
+ @click="openSensorConfig"
331
+ />
115
332
  <wd-cell
116
333
  v-if="showSettings"
117
334
  title="系统设置"
@@ -133,6 +350,42 @@ async function clearCache() {
133
350
  />
134
351
  </wd-cell-group>
135
352
  </view>
353
+
354
+ <!-- 检查更新组件 -->
355
+ <wui-update-component
356
+ v-if="showUpdate"
357
+ :baseUrl="updateConfig.baseUrl"
358
+ :hydrocarbonProgramToken="updateConfig.hydrocarbonProgramToken"
359
+ :sourceId="updateConfig.sourceId"
360
+ :appId="updateConfig.appId"
361
+ :show="showVersion"
362
+ @close="showVersion = false"
363
+ />
364
+
365
+ <!-- 传感器配置弹窗 -->
366
+ <wd-popup
367
+ v-if="isYunyin"
368
+ v-model="showSensorConfig"
369
+ position="center"
370
+ :closable="true"
371
+ custom-style="width: 600rpx; border-radius: 16rpx; padding: 40rpx;"
372
+ >
373
+ <view class="sensor-config-popup">
374
+ <view class="popup-title">修改传感器配置</view>
375
+ <view class="popup-item">
376
+ <text class="popup-label">单次听音时长</text>
377
+ <view class="popup-input-box">
378
+ <wd-input-number v-model="listenDuration" :min="1" :max="60" :step="1" />
379
+ <text class="popup-unit">秒</text>
380
+ </view>
381
+ </view>
382
+ <view class="popup-btn-box">
383
+ <wd-button @click="showSensorConfig = false">取消</wd-button>
384
+ <wd-button type="primary" @click="saveSensorConfig">确认</wd-button>
385
+ </view>
386
+ </view>
387
+ </wd-popup>
388
+
136
389
  <wd-dialog />
137
390
  </view>
138
391
  </template>
@@ -203,5 +456,99 @@ async function clearCache() {
203
456
  align-items: center;
204
457
  }
205
458
  }
459
+
460
+ // 传感器状态卡片
461
+ .card-box {
462
+ padding: 15px;
463
+ padding-top: 0;
464
+
465
+ .card {
466
+ background-color: #fff;
467
+ border-radius: 10px;
468
+ padding: 20px;
469
+ box-shadow: rgba(17, 17, 26, 0.1) 0px 0px 16px;
470
+
471
+ &.card-dark {
472
+ background-color: #161616;
473
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
474
+ }
475
+
476
+ &.card-dark .item {
477
+ border-bottom-color: rgba(255, 255, 255, 0.06);
478
+ }
479
+
480
+ .item {
481
+ display: flex;
482
+ justify-content: space-between;
483
+ align-items: center;
484
+ padding: 20rpx 0;
485
+ border-bottom: 1px solid #f5f5f5;
486
+ font-size: 14px;
487
+
488
+ &:last-child {
489
+ border-bottom: none;
490
+ }
491
+
492
+ .label {
493
+ color: #ccc;
494
+ }
495
+
496
+ .text-dark {
497
+ color: rgba(255, 255, 255, 0.85);
498
+ }
499
+
500
+ .sensor-status {
501
+ display: flex;
502
+ align-items: center;
503
+
504
+ .sensor-text {
505
+ margin-right: 30rpx;
506
+ }
507
+ }
508
+ }
509
+ }
510
+ }
511
+
512
+ // 传感器配置弹窗样式
513
+ .sensor-config-popup {
514
+ .popup-title {
515
+ font-size: 34rpx;
516
+ font-weight: 600;
517
+ text-align: center;
518
+ margin-bottom: 40rpx;
519
+ color: #333;
520
+ }
521
+
522
+ .popup-item {
523
+ display: flex;
524
+ align-items: center;
525
+ justify-content: space-between;
526
+ padding: 20rpx 0;
527
+ margin-bottom: 20rpx;
528
+
529
+ .popup-label {
530
+ font-size: 28rpx;
531
+ color: #666;
532
+ }
533
+
534
+ .popup-input-box {
535
+ display: flex;
536
+ align-items: center;
537
+
538
+ .popup-unit {
539
+ font-size: 26rpx;
540
+ color: #999;
541
+ margin-left: 12rpx;
542
+ }
543
+ }
544
+ }
545
+
546
+ .popup-btn-box {
547
+ display: flex;
548
+ justify-content: flex-end;
549
+ gap: 20rpx;
550
+ margin-top: 40rpx;
551
+ }
552
+ }
206
553
  }
207
554
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.41",
3
+ "version": "1.2.43",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",