bodyParams.nvue 9.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="placeholder"></view>
  12. </view>
  13. <text class="tipTxt">请录入体形参数,用于精准定位穴位</text>
  14. <scroll-view class="formArea" scroll-y="true">
  15. <!-- 用户姓名 -->
  16. <view class="formItem">
  17. <text class="formLabel">姓名</text>
  18. <view class="inputWrap">
  19. <input class="formInput" v-model="form.name" placeholder="请输入姓名" placeholder-class="pholder" maxlength="10" />
  20. </view>
  21. </view>
  22. <!-- 性别 -->
  23. <view class="formItem">
  24. <text class="formLabel">性别</text>
  25. <view class="genderRow">
  26. <view class="genderBtn" :class="{'genderActive': form.gender === 1}" @click="form.gender = 1">
  27. <text class="genderTxt" :style="{color: form.gender === 1 ? '#FFFFFF' : '#545F71'}">男</text>
  28. </view>
  29. <view class="genderBtn" :class="{'genderActive': form.gender === 2}" @click="form.gender = 2">
  30. <text class="genderTxt" :style="{color: form.gender === 2 ? '#FFFFFF' : '#545F71'}">女</text>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 年龄 -->
  35. <view class="formItem">
  36. <text class="formLabel">年龄</text>
  37. <view class="inputWrap">
  38. <input class="formInput" v-model="form.age" type="number" placeholder="例如:28" placeholder-class="pholder" maxlength="3" />
  39. <text class="unitTxt">岁</text>
  40. </view>
  41. </view>
  42. <!-- 肩高 -->
  43. <view class="formItem">
  44. <text class="formLabel">肩高(地面到肩膀的高度)</text>
  45. <view class="inputWrap">
  46. <input class="formInput" v-model="form.shoulderHeight" type="digit" placeholder="例如:135" placeholder-class="pholder" />
  47. <text class="unitTxt">cm</text>
  48. </view>
  49. <view class="sliderWrap">
  50. <slider :value="Number(form.shoulderHeight) || 100" :min="50" :max="250" :step="1"
  51. activeColor="#389588" backgroundColor="#E8E8E8" block-size="20"
  52. @change="onShoulderHeightChange" />
  53. <view class="sliderRange">
  54. <text class="rangeTxt">50cm</text>
  55. <text class="rangeTxt">250cm</text>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 肩宽 -->
  60. <view class="formItem">
  61. <text class="formLabel">肩宽(两肩之间的宽度)</text>
  62. <view class="inputWrap">
  63. <input class="formInput" v-model="form.shoulderWidth" type="digit" placeholder="例如:42" placeholder-class="pholder" />
  64. <text class="unitTxt">cm</text>
  65. </view>
  66. <view class="sliderWrap">
  67. <slider :value="Number(form.shoulderWidth) || 40" :min="20" :max="80" :step="1"
  68. activeColor="#389588" backgroundColor="#E8E8E8" block-size="20"
  69. @change="onShoulderWidthChange" />
  70. <view class="sliderRange">
  71. <text class="rangeTxt">20cm</text>
  72. <text class="rangeTxt">80cm</text>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- 体重 -->
  77. <view class="formItem">
  78. <text class="formLabel">体重</text>
  79. <view class="inputWrap">
  80. <input class="formInput" v-model="form.weight" type="digit" placeholder="例如:65" placeholder-class="pholder" />
  81. <text class="unitTxt">kg</text>
  82. </view>
  83. </view>
  84. <!-- 保存按钮 -->
  85. <view class="saveBtn" @click="onSave">
  86. <text class="saveTxt">保存</text>
  87. </view>
  88. <view class="bottomSpace"></view>
  89. </scroll-view>
  90. </view>
  91. <ay-toast ref="ayToast" />
  92. </view>
  93. </template>
  94. <script>
  95. import ayToast from '@/components/ay-toast/ay-toast.nvue'
  96. export default {
  97. components: {
  98. ayToast
  99. },
  100. data() {
  101. return {
  102. statusBarHeight: 44,
  103. mode: 'add', // add / edit
  104. userId: '',
  105. form: {
  106. name: '',
  107. gender: 1,
  108. age: '',
  109. shoulderHeight: '',
  110. shoulderWidth: '',
  111. weight: ''
  112. }
  113. }
  114. },
  115. onLoad(options) {
  116. const sysInfo = uni.getSystemInfoSync()
  117. this.statusBarHeight = sysInfo.statusBarHeight || 44
  118. this.mode = options.mode || 'add'
  119. this.userId = options.userId || ''
  120. if (this.mode === 'edit' && this.userId) {
  121. this.loadUserData()
  122. }
  123. },
  124. methods: {
  125. goBack() {
  126. uni.navigateBack()
  127. },
  128. /** 加载编辑数据 */
  129. loadUserData() {
  130. const list = uni.getStorageSync('user_manage_list') || []
  131. const user = list.find(u => u.id === this.userId)
  132. if (user) {
  133. this.form.name = user.name || ''
  134. this.form.gender = user.gender || 1
  135. this.form.age = user.age ? String(user.age) : ''
  136. this.form.shoulderHeight = user.shoulderHeight ? String(user.shoulderHeight) : ''
  137. this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
  138. this.form.weight = user.weight ? String(user.weight) : ''
  139. }
  140. },
  141. onShoulderHeightChange(e) {
  142. this.form.shoulderHeight = String(e.detail.value)
  143. },
  144. onShoulderWidthChange(e) {
  145. this.form.shoulderWidth = String(e.detail.value)
  146. },
  147. /** 校验并保存 */
  148. onSave() {
  149. // 校验
  150. if (!this.form.name.trim()) {
  151. this.$refs.ayToast.error('请输入姓名')
  152. return
  153. }
  154. const height = Number(this.form.shoulderHeight)
  155. if (!height || height < 50 || height > 250) {
  156. this.$refs.ayToast.error('肩高范围为50-250cm')
  157. return
  158. }
  159. const width = Number(this.form.shoulderWidth)
  160. if (!width || width < 20 || width > 80) {
  161. this.$refs.ayToast.error('肩宽范围为20-80cm')
  162. return
  163. }
  164. const weight = Number(this.form.weight)
  165. if (!weight || weight < 10 || weight > 300) {
  166. this.$refs.ayToast.error('体重范围为10-300kg')
  167. return
  168. }
  169. let list = uni.getStorageSync('user_manage_list') || []
  170. if (this.mode === 'add') {
  171. // 再次检查是否超过10个
  172. if (list.length >= 10) {
  173. this.$refs.ayToast.error('最多可添加10个用户')
  174. return
  175. }
  176. const newUser = {
  177. id: 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 6),
  178. name: this.form.name.trim(),
  179. gender: this.form.gender,
  180. age: Number(this.form.age) || 0,
  181. shoulderHeight: height,
  182. shoulderWidth: width,
  183. weight: weight,
  184. createTime: Date.now()
  185. }
  186. list.push(newUser)
  187. uni.setStorageSync('user_manage_list', list)
  188. // 如果是第一个用户,自动设为当前用户
  189. if (list.length === 1) {
  190. uni.setStorageSync('current_manage_user_id', newUser.id)
  191. uni.setStorageSync('current_manage_user', newUser)
  192. }
  193. this.$refs.ayToast.success('添加成功')
  194. } else {
  195. // 编辑模式
  196. const index = list.findIndex(u => u.id === this.userId)
  197. if (index === -1) {
  198. this.$refs.ayToast.error('用户信息已过期,请刷新')
  199. return
  200. }
  201. list[index] = {
  202. ...list[index],
  203. name: this.form.name.trim(),
  204. gender: this.form.gender,
  205. age: Number(this.form.age) || 0,
  206. shoulderHeight: height,
  207. shoulderWidth: width,
  208. weight: weight
  209. }
  210. uni.setStorageSync('user_manage_list', list)
  211. // 如果编辑的是当前用户,更新当前用户缓存
  212. const curId = uni.getStorageSync('current_manage_user_id')
  213. if (curId === this.userId) {
  214. uni.setStorageSync('current_manage_user', list[index])
  215. }
  216. this.$refs.ayToast.success('保存成功')
  217. }
  218. setTimeout(() => {
  219. uni.navigateBack()
  220. }, 800)
  221. }
  222. }
  223. }
  224. </script>
  225. <style>
  226. .page {
  227. flex: 1;
  228. position: relative;
  229. }
  230. .content-bg {
  231. position: absolute;
  232. left: 0;
  233. top: 0;
  234. width: 750rpx;
  235. height: 2000px;
  236. }
  237. .pageContent {
  238. flex: 1;
  239. background-image: linear-gradient(to bottom, rgba(56,149,136,1), rgba(56,149,136,0.5));
  240. }
  241. .status-bar {
  242. background-color: rgba(0,0,0,0);
  243. }
  244. .customHead {
  245. flex-direction: row;
  246. justify-content: space-between;
  247. align-items: center;
  248. height: 88rpx;
  249. padding-left: 30rpx;
  250. padding-right: 30rpx;
  251. }
  252. .back-wrap {
  253. width: 50rpx;
  254. height: 50rpx;
  255. justify-content: center;
  256. align-items: center;
  257. }
  258. .backimg {
  259. width: 50rpx;
  260. height: 50rpx;
  261. }
  262. .customTitle {
  263. font-weight: bold;
  264. font-size: 32rpx;
  265. color: #FFFFFF;
  266. }
  267. .placeholder {
  268. width: 50rpx;
  269. }
  270. .tipTxt {
  271. font-size: 24rpx;
  272. color: rgba(255,255,255,0.7);
  273. margin-left: 38rpx;
  274. margin-top: 10rpx;
  275. margin-bottom: 20rpx;
  276. }
  277. .formArea {
  278. flex: 1;
  279. padding-left: 30rpx;
  280. padding-right: 30rpx;
  281. }
  282. .formItem {
  283. background-color: #FFFFFF;
  284. border-radius: 16rpx;
  285. padding: 28rpx;
  286. margin-bottom: 20rpx;
  287. }
  288. .formLabel {
  289. font-size: 26rpx;
  290. color: #9BA5B7;
  291. margin-bottom: 16rpx;
  292. }
  293. .inputWrap {
  294. flex-direction: row;
  295. align-items: center;
  296. background-color: #F5F7FA;
  297. border-radius: 12rpx;
  298. padding-left: 20rpx;
  299. padding-right: 20rpx;
  300. height: 80rpx;
  301. }
  302. .formInput {
  303. flex: 1;
  304. font-size: 30rpx;
  305. color: #333333;
  306. }
  307. .unitTxt {
  308. font-size: 26rpx;
  309. color: #9BA5B7;
  310. margin-left: 10rpx;
  311. }
  312. .genderRow {
  313. flex-direction: row;
  314. }
  315. .genderBtn {
  316. width: 160rpx;
  317. height: 72rpx;
  318. border-radius: 36rpx;
  319. background-color: #F5F7FA;
  320. justify-content: center;
  321. align-items: center;
  322. margin-right: 24rpx;
  323. }
  324. .genderActive {
  325. background-color: #389588;
  326. }
  327. .genderTxt {
  328. font-size: 28rpx;
  329. }
  330. .sliderWrap {
  331. margin-top: 20rpx;
  332. }
  333. .sliderRange {
  334. flex-direction: row;
  335. justify-content: space-between;
  336. margin-top: 4rpx;
  337. }
  338. .rangeTxt {
  339. font-size: 22rpx;
  340. color: #9BA5B7;
  341. }
  342. .saveBtn {
  343. background-color: #389588;
  344. border-radius: 44rpx;
  345. height: 88rpx;
  346. justify-content: center;
  347. align-items: center;
  348. margin-top: 30rpx;
  349. margin-left: 20rpx;
  350. margin-right: 20rpx;
  351. }
  352. .saveTxt {
  353. font-size: 32rpx;
  354. color: #FFFFFF;
  355. font-weight: bold;
  356. }
  357. .bottomSpace {
  358. height: 60rpx;
  359. }
  360. </style>