userManage.nvue 8.4 KB

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