userManage.nvue 9.7 KB

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