wui-components-v2 1.2.42 → 1.2.44

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.
@@ -91,24 +91,74 @@ const cellGroupStyle = computed(() => ({
91
91
  backgroundColor: isDark.value ? '#111111' : 'transparent',
92
92
  borderRadius: isDark.value ? '10px' : '0',
93
93
  }))
94
- const user = useUser().getUserInfo()
95
94
  const dialog = useDialog()
96
95
  const toast = useGlobalToast()
96
+
97
+ const storeUser = useUser().getUserInfo()
97
98
  const userInfo = ref({
98
- name: user.name,
99
- nickName: user.nickName,
99
+ name: storeUser.name,
100
+ nickName: storeUser.nickName,
101
+ tenantName: storeUser.tenantName ?? storeUser.tenant_name ?? '',
100
102
  })
103
+ // 租户名称:优先取外部传入的 prop,否则从用户信息中读取
104
+ const tenantName = computed(() => props.tenantName || userInfo.value.tenantName)
105
+
106
+ // 组件内部自行获取用户信息(含租户名称等实体字段),保持组件独立封装
107
+ async function fetchUserInfo() {
108
+ try {
109
+ const res = await getUserConfig()
110
+ if (res?.status !== 'success' || !res.user) return
111
+ const user = res.user
112
+ // user.name / user.nickName 为顶层字段,直接读取
113
+ userInfo.value = {
114
+ name: user.name || userInfo.value.name,
115
+ nickName: user.nickName || userInfo.value.nickName,
116
+ tenantName: userInfo.value.tenantName,
117
+ }
118
+ // 查询用户实体,实体字段为中文 key(姓名/账号/维修厂等),
119
+ // sourceId 为用户实体 x4u6aJ6IQQ,按实体 code 字段匹配当前用户 id
120
+ const sourceId = 'x4u6aJ6IQQ'
121
+ if (user.id) {
122
+ const entityRes = await req({
123
+ url: `/v3/mstruc/data?sourceId=${sourceId}&depth=1&pageNo=1&pageSize=1&c_code_equals=${user.id}&c_标记删除_equals=否`,
124
+ method: 'GET',
125
+ })
126
+ const list = entityRes?.entities || entityRes?.data?.entities || []
127
+ const entity = list[0]
128
+ if (entity) {
129
+ userInfo.value = {
130
+ name: entity['姓名'] || userInfo.value.name,
131
+ nickName: entity['账号'] || userInfo.value.nickName,
132
+ tenantName: entity['维修厂'] || userInfo.value.tenantName,
133
+ }
134
+ }
135
+ }
136
+ } catch (error) {
137
+ console.error('获取用户信息失败:', error)
138
+ }
139
+ }
101
140
 
102
141
  // ==================== 传感器状态 ====================
103
142
  const showVersion = ref(false) // 更新版本开关
104
143
  const showSensorConfig = ref(false) // 传感器配置弹窗开关
105
144
  const listenDuration = ref(2) // 单次听音时长,默认2秒
106
145
  const sensor = ref(0) // 传感器在线状态 1:在线 0:离线
107
- const sensorCode = ref(props.sensorCode || uni.getStorageSync('sensorCode') || '')
146
+ // 传感器编号:优先外部传入 prop,其次本地缓存 sensorCode,再尝试从 userInfo 缓存读取
147
+ const sensorCode = ref(
148
+ props.sensorCode ||
149
+ uni.getStorageSync('sensorCode') ||
150
+ uni.getStorageSync('userInfo')?.sensorCode ||
151
+ ''
152
+ )
108
153
 
109
154
  onShow(() => {
155
+ // 组件内部获取用户信息(租户名称等),保持独立
156
+ fetchUserInfo()
110
157
  if (!props.sensorCode) {
111
- sensorCode.value = uni.getStorageSync('sensorCode') || ''
158
+ sensorCode.value =
159
+ uni.getStorageSync('sensorCode') ||
160
+ uni.getStorageSync('userInfo')?.sensorCode ||
161
+ ''
112
162
  }
113
163
  if (props.showSensorStatus) {
114
164
  getSensorInfo()
@@ -123,7 +173,7 @@ function resolveSensorStatus(res: any): number {
123
173
  }
124
174
 
125
175
  // 获取传感器在线信息
126
- const getSensorInfo = async (cli?: string) => {
176
+ async function getSensorInfo(cli?: string) {
127
177
  let code = sensorCode.value
128
178
  let newCode = code ? code.slice(3) : ''
129
179
  if (!newCode) return
@@ -239,14 +289,14 @@ function saveSensorConfig() {
239
289
  />
240
290
  <view class="user-text">
241
291
  <view class="user-name">{{ userInfo.name }}</view>
242
- <view class="user-nickname">昵称:{{ userInfo.nickName }}</view>
292
+ <view class="user-nickname">账号:{{ userInfo.nickName }}</view>
243
293
  </view>
244
294
  </view>
245
295
  </view>
246
296
  </view>
247
297
 
248
298
  <!-- 传感器状态卡片 -->
249
- <view v-if="isYunyin" class="card-box">
299
+ <view v-if="showSensorStatus" class="card-box">
250
300
  <view class="card" :class="{ 'card-dark': isDark }">
251
301
  <view class="item">
252
302
  <text class="label">租户名称</text>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.42",
3
+ "version": "1.2.44",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",