userManage.nvue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="page">
  3. <image class="content-bg" src="/static/device/devicebg.png" mode="scaleToFill"></image>
  4. <view class="pageContent">
  5. <view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
  6. <view class="customHead">
  7. <view class="back-wrap" @click="goBack">
  8. <image src="/static/public/back.png" mode="aspectFill" class="backimg"></image>
  9. </view>
  10. <text class="customTitle">用户管理</text>
  11. <view class="plus" @click="addUser">
  12. <text class="plusTxt">+ 新增</text>
  13. </view>
  14. </view>
  15. <text class="tipTxt">最多可添加10个用户,点击卡片切换用户</text>
  16. <scroll-view class="userList" scroll-y="true">
  17. <view class="listInner">
  18. <view class="cardWrap" :class="{'curCardWrap': item.id === currentUserId}"
  19. v-for="(item, index) in userList" :key="item.id" @click="switchUser(item)">
  20. <view class="userCard">
  21. <view class="userInfo">
  22. <view class="avatarWrap">
  23. <text class="avatarTxt">{{item.name ? item.name.substring(0,1) : '用'}}</text>
  24. </view>
  25. <view class="infoDetail">
  26. <view class="nameRow">
  27. <text class="userName">{{item.name}}</text>
  28. <text class="userGender">{{item.gender === 1 ? '男' : '女'}}</text>
  29. <text class="userAge" v-if="item.age">{{item.age}}岁</text>
  30. </view>
  31. <view class="bodyRow">
  32. <text class="bodyTxt">身长:{{item.bodyHeight || item.shoulderHeight || '--'}}cm</text>
  33. <text class="bodyTxt">肩宽:{{item.shoulderWidth || '--'}}cm</text>
  34. <text class="bodyTxt">脊柱:{{item.spineLength || '--'}}cm</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="cardBtns">
  39. <text class="fingerBtn" @click.stop="enrollFingerprint(item)">录入指纹</text>
  40. <text class="editBtn" @click.stop="editUser(item)">编辑</text>
  41. <text class="deleteBtn" @click.stop="confirmDelete(item)">删除</text>
  42. </view>
  43. <view class="curTag" v-if="item.id === currentUserId">
  44. <text class="curTagTxt">当前</text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. <!-- 删除确认弹框 -->
  52. <customPopup :isShow="showDeletePopup" @closePop="showDeletePopup=false">
  53. <view class="deletePopContent">
  54. <text class="deleteTip">确定删除用户"{{deleteTarget ? deleteTarget.name : ''}}"?</text>
  55. <text class="deleteSub">删除后将无法恢复</text>
  56. <view class="deleteBtns">
  57. <view class="dBtn cancelBtn" @click="showDeletePopup=false">
  58. <text class="dBtnTxt">取消</text>
  59. </view>
  60. <view class="dBtn redBtn" @click="doDelete">
  61. <text class="dBtnTxt redTxt">确定删除</text>
  62. </view>
  63. </view>
  64. </view>
  65. </customPopup>
  66. <ay-toast ref="ayToast" />
  67. </view>
  68. </template>
  69. <script>
  70. import customPopup from '@/components/customPopup/customPopup.nvue'
  71. import ayToast from '@/components/ay-toast/ay-toast.nvue'
  72. import { getGroupMembers } from '@/utils/api/device'
  73. export default {
  74. components: {
  75. customPopup,
  76. ayToast
  77. },
  78. data() {
  79. return {
  80. statusBarHeight: 44,
  81. userList: [],
  82. currentUserId: '',
  83. showDeletePopup: false,
  84. deleteTarget: null
  85. }
  86. },
  87. onLoad() {
  88. const sysInfo = uni.getSystemInfoSync()
  89. this.statusBarHeight = sysInfo.statusBarHeight || 44
  90. },
  91. onShow() {
  92. this.loadUsers()
  93. },
  94. methods: {
  95. goBack() {
  96. uni.navigateBack()
  97. },
  98. /** 从后端加载当前设备用户列表 */
  99. async loadUsers() {
  100. const currentDevice = uni.getStorageSync('current_device') || {}
  101. let list = []
  102. if (currentDevice.groupId) {
  103. try {
  104. const data = await getGroupMembers(currentDevice.groupId)
  105. list = (data || []).map(this.normalizeMember)
  106. uni.setStorageSync('user_manage_list', list)
  107. } catch (e) {
  108. console.error('加载群组成员失败,使用本地缓存', e)
  109. list = uni.getStorageSync('user_manage_list') || []
  110. }
  111. } else {
  112. const currentUser = uni.getStorageSync('current_manage_user') || currentDevice.profile
  113. list = currentUser ? [this.normalizeMember(currentUser)] : []
  114. uni.setStorageSync('user_manage_list', list)
  115. }
  116. this.userList = list
  117. this.currentUserId = String(uni.getStorageSync('current_manage_user_id') || '')
  118. // 如果没有当前用户且列表不为空,默认选中第一个
  119. if (!this.currentUserId && list.length > 0) {
  120. this.currentUserId = String(list[0].id)
  121. uni.setStorageSync('current_manage_user_id', this.currentUserId)
  122. uni.setStorageSync('current_manage_user', list[0])
  123. }
  124. },
  125. normalizeMember(item) {
  126. return {
  127. ...item,
  128. id: String(item.profileId || item.id),
  129. bodyHeight: item.bodyHeight || item.shoulderHeight || '',
  130. profileComplete: !!item.profileComplete
  131. }
  132. },
  133. /** 切换用户 */
  134. switchUser(item) {
  135. this.currentUserId = String(item.id)
  136. uni.setStorageSync('current_manage_user_id', this.currentUserId)
  137. uni.setStorageSync('current_manage_user', item)
  138. this.$refs.ayToast.success('已切换至用户:' + item.name)
  139. setTimeout(() => {
  140. uni.navigateBack()
  141. }, 800)
  142. },
  143. /** 新增用户 */
  144. addUser() {
  145. if (this.userList.length >= 10) {
  146. this.$refs.ayToast.error('最多可添加10个用户,请先删除其他用户')
  147. return
  148. }
  149. uni.navigateTo({
  150. url: '/pages/device/bodyParams/bodyParams?mode=add'
  151. })
  152. },
  153. /** 编辑用户 */
  154. editUser(item) {
  155. uni.navigateTo({
  156. url: '/pages/device/bodyParams/bodyParams?mode=edit&userId=' + item.id
  157. })
  158. },
  159. /** 确认删除 */
  160. confirmDelete(item) {
  161. this.$refs.ayToast.error('暂不支持在App端删除群组成员')
  162. },
  163. /** 录入指纹 */
  164. enrollFingerprint(item) {
  165. this.$refs.ayToast.loading("指纹录入中", { mask: false })
  166. },
  167. /** 执行删除 */
  168. doDelete() {
  169. if (!this.deleteTarget) return
  170. const id = this.deleteTarget.id
  171. this.userList = this.userList.filter(u => u.id !== id)
  172. uni.setStorageSync('user_manage_list', this.userList)
  173. // 如果删除的是当前用户,切换到第一个
  174. if (this.currentUserId === id && this.userList.length > 0) {
  175. this.currentUserId = this.userList[0].id
  176. uni.setStorageSync('current_manage_user_id', this.currentUserId)
  177. uni.setStorageSync('current_manage_user', this.userList[0])
  178. }
  179. this.showDeletePopup = false
  180. this.deleteTarget = null
  181. this.$refs.ayToast.success('删除成功')
  182. }
  183. }
  184. }
  185. </script>
  186. <style>
  187. .page {
  188. flex: 1;
  189. position: relative;
  190. }
  191. .content-bg {
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. width: 750rpx;
  196. height: 2000px;
  197. }
  198. .pageContent {
  199. flex: 1;
  200. background-image: linear-gradient(to bottom, rgba(56,149,136,1), rgba(56,149,136,0.5));
  201. }
  202. .status-bar {
  203. background-color: rgba(0,0,0,0);
  204. }
  205. .customHead {
  206. flex-direction: row;
  207. justify-content: space-between;
  208. align-items: center;
  209. height: 88rpx;
  210. padding-left: 30rpx;
  211. padding-right: 30rpx;
  212. }
  213. .back-wrap {
  214. width: 50rpx;
  215. height: 50rpx;
  216. justify-content: center;
  217. align-items: center;
  218. }
  219. .backimg {
  220. width: 50rpx;
  221. height: 50rpx;
  222. }
  223. .customTitle {
  224. font-weight: bold;
  225. font-size: 32rpx;
  226. color: #FFFFFF;
  227. }
  228. .plus {
  229. padding-left: 16rpx;
  230. padding-right: 16rpx;
  231. padding-top: 8rpx;
  232. padding-bottom: 8rpx;
  233. background-color: rgba(255,255,255,0.2);
  234. border-radius: 24rpx;
  235. }
  236. .plusTxt {
  237. font-size: 26rpx;
  238. color: #FFFFFF;
  239. }
  240. .tipTxt {
  241. font-size: 24rpx;
  242. color: rgba(255,255,255,0.7);
  243. margin-left: 38rpx;
  244. margin-top: 10rpx;
  245. margin-bottom: 20rpx;
  246. }
  247. .userList {
  248. flex: 1;
  249. }
  250. .listInner {
  251. padding-left: 30rpx;
  252. padding-right: 30rpx;
  253. padding-top: 20rpx;
  254. padding-bottom: 30rpx;
  255. }
  256. .cardWrap {
  257. border-radius: 20rpx;
  258. overflow: hidden;
  259. margin-bottom: 24rpx;
  260. background-color: #389588;
  261. }
  262. .curCardWrap {
  263. border-radius: 20rpx;
  264. }
  265. .userCard {
  266. background-color: #FFFFFF;
  267. border-radius: 20rpx;
  268. padding: 30rpx;
  269. position: relative;
  270. }
  271. .userInfo {
  272. flex-direction: row;
  273. align-items: center;
  274. }
  275. .avatarWrap {
  276. width: 80rpx;
  277. height: 80rpx;
  278. border-radius: 80rpx;
  279. background-color: #389588;
  280. justify-content: center;
  281. align-items: center;
  282. margin-right: 20rpx;
  283. }
  284. .avatarTxt {
  285. font-size: 32rpx;
  286. color: #FFFFFF;
  287. font-weight: bold;
  288. }
  289. .infoDetail {
  290. flex: 1;
  291. }
  292. .nameRow {
  293. flex-direction: row;
  294. align-items: center;
  295. margin-bottom: 8rpx;
  296. }
  297. .userName {
  298. font-size: 30rpx;
  299. color: #333333;
  300. font-weight: bold;
  301. margin-right: 16rpx;
  302. }
  303. .userGender {
  304. font-size: 24rpx;
  305. color: #9BA5B7;
  306. margin-right: 12rpx;
  307. }
  308. .userAge {
  309. font-size: 24rpx;
  310. color: #9BA5B7;
  311. }
  312. .bodyRow {
  313. flex-direction: row;
  314. }
  315. .bodyTxt {
  316. font-size: 24rpx;
  317. color: #9BA5B7;
  318. margin-right: 20rpx;
  319. }
  320. .cardBtns {
  321. flex-direction: row;
  322. justify-content: flex-end;
  323. margin-top: 20rpx;
  324. }
  325. .fingerBtn {
  326. font-size: 26rpx;
  327. color: #E6A23C;
  328. padding-left: 24rpx;
  329. padding-right: 24rpx;
  330. padding-top: 10rpx;
  331. padding-bottom: 10rpx;
  332. border-radius: 24rpx;
  333. background-color: #FDF6EC;
  334. margin-right: 20rpx;
  335. }
  336. .editBtn {
  337. font-size: 26rpx;
  338. color: #389588;
  339. padding-left: 24rpx;
  340. padding-right: 24rpx;
  341. padding-top: 10rpx;
  342. padding-bottom: 10rpx;
  343. border-radius: 24rpx;
  344. background-color: #F0F8F7;
  345. margin-right: 20rpx;
  346. }
  347. .deleteBtn {
  348. font-size: 26rpx;
  349. color: #F65252;
  350. padding-left: 24rpx;
  351. padding-right: 24rpx;
  352. padding-top: 10rpx;
  353. padding-bottom: 10rpx;
  354. border-radius: 24rpx;
  355. background-color: #FFF2F2;
  356. }
  357. .curTag {
  358. position: absolute;
  359. right: 0;
  360. top: 0;
  361. background-color: #389588;
  362. padding-left: 16rpx;
  363. padding-right: 16rpx;
  364. padding-top: 4rpx;
  365. padding-bottom: 4rpx;
  366. border-bottom-left-radius: 12rpx;
  367. border-top-right-radius: 18rpx;
  368. }
  369. .curTagTxt {
  370. font-size: 20rpx;
  371. color: #FFFFFF;
  372. }
  373. /* 删除弹框 */
  374. .deletePopContent {
  375. align-items: center;
  376. padding-top: 20rpx;
  377. }
  378. .deleteTip {
  379. font-size: 32rpx;
  380. color: #333333;
  381. font-weight: bold;
  382. margin-bottom: 16rpx;
  383. }
  384. .deleteSub {
  385. font-size: 26rpx;
  386. color: #9BA5B7;
  387. margin-bottom: 40rpx;
  388. }
  389. .deleteBtns {
  390. flex-direction: row;
  391. justify-content: center;
  392. }
  393. .dBtn {
  394. width: 260rpx;
  395. height: 80rpx;
  396. border-radius: 40rpx;
  397. justify-content: center;
  398. align-items: center;
  399. margin-left: 20rpx;
  400. margin-right: 20rpx;
  401. }
  402. .cancelBtn {
  403. background-color: #F3F3F3;
  404. }
  405. .redBtn {
  406. background-color: #F65252;
  407. }
  408. .dBtnTxt {
  409. font-size: 28rpx;
  410. color: #545F71;
  411. }
  412. .redTxt {
  413. color: #FFFFFF;
  414. }
  415. </style>