userManage.nvue 9.0 KB

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