wui-components-v2 1.2.41 → 1.2.42

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()
@@ -47,6 +99,62 @@ const userInfo = ref({
47
99
  nickName: user.nickName,
48
100
  })
49
101
 
102
+ // ==================== 传感器状态 ====================
103
+ const showVersion = ref(false) // 更新版本开关
104
+ const showSensorConfig = ref(false) // 传感器配置弹窗开关
105
+ const listenDuration = ref(2) // 单次听音时长,默认2秒
106
+ const sensor = ref(0) // 传感器在线状态 1:在线 0:离线
107
+ const sensorCode = ref(props.sensorCode || uni.getStorageSync('sensorCode') || '')
108
+
109
+ onShow(() => {
110
+ if (!props.sensorCode) {
111
+ sensorCode.value = uni.getStorageSync('sensorCode') || ''
112
+ }
113
+ if (props.showSensorStatus) {
114
+ getSensorInfo()
115
+ }
116
+ })
117
+
118
+ // 从返回结果中提取在线状态(兼容 1/0、true/false、嵌套 data 等结构)
119
+ function resolveSensorStatus(res: any): number {
120
+ const value = res && typeof res === 'object' ? (res.data ?? res) : res
121
+ if (typeof value === 'boolean') return value ? 1 : 0
122
+ return Number(value) ? 1 : 0
123
+ }
124
+
125
+ // 获取传感器在线信息
126
+ const getSensorInfo = async (cli?: string) => {
127
+ let code = sensorCode.value
128
+ let newCode = code ? code.slice(3) : ''
129
+ if (!newCode) return
130
+ if (cli) {
131
+ toast.show({ msg: '传感器状态更新中' })
132
+ }
133
+ try {
134
+ if (props.sensorOnlineApi) {
135
+ const res = await props.sensorOnlineApi({ sensorCode: newCode })
136
+ sensor.value = resolveSensorStatus(res)
137
+ } else {
138
+ const res = await req({
139
+ url: `/v3/mstruc/sensor/online`,
140
+ method: 'GET',
141
+ data: { sensorCode: newCode },
142
+ })
143
+ sensor.value = resolveSensorStatus(res)
144
+ }
145
+ if (cli) {
146
+ toast.success({ msg: '传感器状态更新成功' })
147
+ }
148
+ } catch (error) {
149
+ console.error('传感器状态查询失败:', error)
150
+ if (cli) {
151
+ toast.error({ msg: '传感器状态更新失败' })
152
+ }
153
+ }
154
+ }
155
+
156
+ // ==================== 功能入口 ====================
157
+
50
158
  // 退出登录
51
159
  function quit() {
52
160
  dialog
@@ -77,6 +185,33 @@ async function clearCache() {
77
185
  uni.setStorageSync('userInfo', res.user)
78
186
  }
79
187
  }
188
+
189
+ // 传感器绑定
190
+ function bind() {
191
+ uni.navigateTo({
192
+ url: props.bindPath,
193
+ })
194
+ }
195
+
196
+ // 检查更新
197
+ function queryVersion() {
198
+ showVersion.value = true
199
+ }
200
+
201
+ // 打开传感器配置弹窗
202
+ function openSensorConfig() {
203
+ // 从本地读取已保存的听音时长,默认2秒
204
+ const savedDuration = uni.getStorageSync('listenDuration')
205
+ listenDuration.value = savedDuration ? Number(savedDuration) : 2
206
+ showSensorConfig.value = true
207
+ }
208
+
209
+ // 保存传感器配置
210
+ function saveSensorConfig() {
211
+ uni.setStorageSync('listenDuration', listenDuration.value)
212
+ toast.success({ msg: '传感器配置保存成功' })
213
+ showSensorConfig.value = false
214
+ }
80
215
  </script>
81
216
 
82
217
  <template>
@@ -110,8 +245,58 @@ async function clearCache() {
110
245
  </view>
111
246
  </view>
112
247
 
248
+ <!-- 传感器状态卡片 -->
249
+ <view v-if="isYunyin" class="card-box">
250
+ <view class="card" :class="{ 'card-dark': isDark }">
251
+ <view class="item">
252
+ <text class="label">租户名称</text>
253
+ <text :class="{ 'text-dark': isDark }">{{ tenantName }}</text>
254
+ </view>
255
+ <view class="item">
256
+ <text class="label">传感器编号</text>
257
+ <text :class="{ 'text-dark': isDark }">{{ sensorCode }}</text>
258
+ </view>
259
+ <view class="item">
260
+ <text class="label">传感器状态</text>
261
+ <view class="sensor-status">
262
+ <text class="sensor-text" :style="{ color: sensor === 1 ? '#2eba8b' : 'red' }">
263
+ {{ sensor === 1 ? '在线' : '离线' }}
264
+ </text>
265
+ <wd-icon name="refresh" size="34rpx" @click="getSensorInfo('c')" />
266
+ </view>
267
+ </view>
268
+ </view>
269
+ </view>
270
+
113
271
  <view class="mx-[15px] rounded-2">
114
272
  <wd-cell-group :custom-style="cellGroupStyle">
273
+ <wd-cell
274
+ v-if="isYunyin"
275
+ title="传感器绑定"
276
+ icon="link"
277
+ :is-link="true"
278
+ :clickable="true"
279
+ :custom-style="cellStyle"
280
+ @click="bind"
281
+ />
282
+ <wd-cell
283
+ v-if="showUpdate"
284
+ title="检查更新"
285
+ icon="refresh"
286
+ :is-link="true"
287
+ :clickable="true"
288
+ :custom-style="cellStyle"
289
+ @click="queryVersion"
290
+ />
291
+ <wd-cell
292
+ v-if="showSensorConfig && isYunyin"
293
+ title="修改传感器配置"
294
+ icon="edit"
295
+ :is-link="true"
296
+ :clickable="true"
297
+ :custom-style="cellStyle"
298
+ @click="openSensorConfig"
299
+ />
115
300
  <wd-cell
116
301
  v-if="showSettings"
117
302
  title="系统设置"
@@ -133,6 +318,42 @@ async function clearCache() {
133
318
  />
134
319
  </wd-cell-group>
135
320
  </view>
321
+
322
+ <!-- 检查更新组件 -->
323
+ <wui-update-component
324
+ v-if="showUpdate"
325
+ :baseUrl="updateConfig.baseUrl"
326
+ :hydrocarbonProgramToken="updateConfig.hydrocarbonProgramToken"
327
+ :sourceId="updateConfig.sourceId"
328
+ :appId="updateConfig.appId"
329
+ :show="showVersion"
330
+ @close="showVersion = false"
331
+ />
332
+
333
+ <!-- 传感器配置弹窗 -->
334
+ <wd-popup
335
+ v-if="isYunyin"
336
+ v-model="showSensorConfig"
337
+ position="center"
338
+ :closable="true"
339
+ custom-style="width: 600rpx; border-radius: 16rpx; padding: 40rpx;"
340
+ >
341
+ <view class="sensor-config-popup">
342
+ <view class="popup-title">修改传感器配置</view>
343
+ <view class="popup-item">
344
+ <text class="popup-label">单次听音时长</text>
345
+ <view class="popup-input-box">
346
+ <wd-input-number v-model="listenDuration" :min="1" :max="60" :step="1" />
347
+ <text class="popup-unit">秒</text>
348
+ </view>
349
+ </view>
350
+ <view class="popup-btn-box">
351
+ <wd-button @click="showSensorConfig = false">取消</wd-button>
352
+ <wd-button type="primary" @click="saveSensorConfig">确认</wd-button>
353
+ </view>
354
+ </view>
355
+ </wd-popup>
356
+
136
357
  <wd-dialog />
137
358
  </view>
138
359
  </template>
@@ -203,5 +424,99 @@ async function clearCache() {
203
424
  align-items: center;
204
425
  }
205
426
  }
427
+
428
+ // 传感器状态卡片
429
+ .card-box {
430
+ padding: 15px;
431
+ padding-top: 0;
432
+
433
+ .card {
434
+ background-color: #fff;
435
+ border-radius: 10px;
436
+ padding: 20px;
437
+ box-shadow: rgba(17, 17, 26, 0.1) 0px 0px 16px;
438
+
439
+ &.card-dark {
440
+ background-color: #161616;
441
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
442
+ }
443
+
444
+ &.card-dark .item {
445
+ border-bottom-color: rgba(255, 255, 255, 0.06);
446
+ }
447
+
448
+ .item {
449
+ display: flex;
450
+ justify-content: space-between;
451
+ align-items: center;
452
+ padding: 20rpx 0;
453
+ border-bottom: 1px solid #f5f5f5;
454
+ font-size: 14px;
455
+
456
+ &:last-child {
457
+ border-bottom: none;
458
+ }
459
+
460
+ .label {
461
+ color: #ccc;
462
+ }
463
+
464
+ .text-dark {
465
+ color: rgba(255, 255, 255, 0.85);
466
+ }
467
+
468
+ .sensor-status {
469
+ display: flex;
470
+ align-items: center;
471
+
472
+ .sensor-text {
473
+ margin-right: 30rpx;
474
+ }
475
+ }
476
+ }
477
+ }
478
+ }
479
+
480
+ // 传感器配置弹窗样式
481
+ .sensor-config-popup {
482
+ .popup-title {
483
+ font-size: 34rpx;
484
+ font-weight: 600;
485
+ text-align: center;
486
+ margin-bottom: 40rpx;
487
+ color: #333;
488
+ }
489
+
490
+ .popup-item {
491
+ display: flex;
492
+ align-items: center;
493
+ justify-content: space-between;
494
+ padding: 20rpx 0;
495
+ margin-bottom: 20rpx;
496
+
497
+ .popup-label {
498
+ font-size: 28rpx;
499
+ color: #666;
500
+ }
501
+
502
+ .popup-input-box {
503
+ display: flex;
504
+ align-items: center;
505
+
506
+ .popup-unit {
507
+ font-size: 26rpx;
508
+ color: #999;
509
+ margin-left: 12rpx;
510
+ }
511
+ }
512
+ }
513
+
514
+ .popup-btn-box {
515
+ display: flex;
516
+ justify-content: flex-end;
517
+ gap: 20rpx;
518
+ margin-top: 40rpx;
519
+ }
520
+ }
206
521
  }
207
522
  </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.42",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",