PersonDetail.uvue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex:1">
  4. <!-- #endif -->
  5. <view class="container">
  6. <view class="download-card">
  7. <form>
  8. <view class="uni-form-item uni-row">
  9. <view class="title">登录账号</view>
  10. <input class="uni-input inputDisabled" name="username" :value="username" disabled = "true"/>
  11. </view>
  12. <view class="uni-form-item uni-row">
  13. <view class="title">用户姓名</view>
  14. <input class="uni-input" name="name" :value="name" @input="inputName"/>
  15. </view>
  16. <view class="uni-form-item uni-row">
  17. <view class="title">新密码</view>
  18. <input class="uni-input" name="password" :password="true" :value="password" @input="inputNew"
  19. placeholder="请输入新密码" />
  20. </view>
  21. <view class="uni-form-item uni-row">
  22. <view class="title">确认密码</view>
  23. <input class="uni-input" name="confirmPassword" :password="true" :value="confirmPassword" @input="inputConfirm"
  24. placeholder="请确认新密码" />
  25. </view>
  26. <button type="primary" @click="submit">提交</button>
  27. </form>
  28. </view>
  29. </view>
  30. <!-- #ifdef APP -->
  31. </scroll-view>
  32. <!-- #endif -->
  33. </template>
  34. <script lang="uts">
  35. import { updateUserPwd } from "@/api/system/user"
  36. import { updateData, getList } from '@/api/work';
  37. import { getCurrentUserSync, getCurrentUserNameSync } from '@/utils/auth.uts'
  38. type User = {
  39. username : string | null,
  40. name : string | null,
  41. password : string | null,
  42. confirmPassword : string | null
  43. }
  44. export default {
  45. data() {
  46. return {
  47. id: '',
  48. username: '',
  49. name: '',
  50. password: '',
  51. confirmPassword: '',
  52. user: {
  53. username: null,
  54. name: null,
  55. password: null,
  56. confirmPassword: null
  57. } as User,
  58. }
  59. },
  60. onBackPress() {
  61. // 覆盖系统默认的返回行为,返回到指定页面
  62. uni.navigateTo({
  63. url: `/pages/mine/person/PersonList`,
  64. // 修改动画方向为从左到右退回
  65. animationType: 'slide-in-left', // 使用从左到右滑出的动画效果
  66. animationDuration: 300 // 动画持续时间,单位ms
  67. })
  68. // 返回true表示拦截默认返回行为
  69. return true
  70. },
  71. onLoad(options) {
  72. // 获取URL参数中的id
  73. const id = options?.['id'] ?? ""
  74. this.id = id
  75. this.getUser(id)
  76. },
  77. methods: {
  78. inputName(event : UniInputEvent) {
  79. this.user.name = event.detail.value
  80. },
  81. inputNew(event : UniInputEvent) {
  82. this.user.password = event.detail.value
  83. },
  84. inputConfirm(event : UniInputEvent) {
  85. this.user.confirmPassword = event.detail.value
  86. },
  87. getUser(userId : string) {
  88. // 使用传入的userId参数获取特定用户的信息
  89. getList('app_user', 'id', userId, null, null, null).then((response : UTSJSONObject) => {
  90. if (response != null && response['data'] != null) {
  91. console.log(response)
  92. // 解析用户数据并设置到页面变量
  93. let dataList = response?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
  94. if (dataList != null && dataList.length > 0) {
  95. let user = dataList[0];
  96. this.username = user.getString('username') ?? '';
  97. this.name = user.getString('name') ?? '';
  98. }
  99. }
  100. })
  101. },
  102. submit() {
  103. if (this.user.password != null && (this.user.password.length < 6 || this.user.password.length > 20)) {
  104. uni.showToast({
  105. title: "长度在6到20个字符",
  106. icon: "error"
  107. })
  108. return
  109. }
  110. if (this.user.confirmPassword != null && (this.user.confirmPassword.length < 6 || this.user.confirmPassword.length > 20)) {
  111. uni.showToast({
  112. title: "长度在6到20个字符",
  113. icon: "error"
  114. })
  115. return
  116. } else if (this.user.confirmPassword != this.user.password) {
  117. uni.showToast({
  118. title: "两次输入的密码不一致",
  119. icon: "error"
  120. })
  121. return
  122. }
  123. if (this.user.name == null && this.user.password == null && this.user.confirmPassword == null) {
  124. uni.showToast({
  125. title: "没有做修改",
  126. icon: "error"
  127. })
  128. return
  129. }
  130. getList('app_user', 'id', this.id, null, null, null).then((res : UTSJSONObject) => {
  131. let userList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
  132. console.log(userList);
  133. if (userList != null && userList.length > 0) {
  134. let user = userList[0];
  135. if (user != null) {
  136. let updatedData = "";
  137. if(this.user.username != null && this.user.username != '') {
  138. updatedData += `username = '` + this.user.username + `' ,`
  139. }
  140. if(this.user.name != null && this.user.name != '') {
  141. updatedData += `name = '` + this.user.name + `' ,`
  142. }
  143. if (this.user.password != null && this.user.password != '') {
  144. updatedData += `password= '` + this.user.password + `' ,`
  145. }
  146. // 移除最后一个多余的逗号(处理可能有空格和无空格的情况)
  147. if (updatedData.endsWith(', ')) {
  148. updatedData = updatedData.slice(0, -2);
  149. } else if (updatedData.endsWith(',')) {
  150. updatedData = updatedData.slice(0, -1);
  151. }
  152. updateData('app_user', updatedData, 'id', this.id).then((res : UTSJSONObject) => {
  153. let data = res?.['data'] as boolean ?? false;
  154. if (data != null && data == true) {
  155. uni.showToast({
  156. title: "更新成功!",
  157. });
  158. setTimeout(() => {
  159. }, 1500)
  160. uni.reLaunch({
  161. url: '/pages/mine/person/PersonList'
  162. });
  163. } else {
  164. uni.showToast({
  165. title: "更新失败,请稍后重试!",
  166. icon: "error"
  167. });
  168. }
  169. });
  170. }
  171. }
  172. });
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scope>
  178. .container {
  179. padding: 10rpx;
  180. background-color: #f0f4f8;
  181. flex: 1;
  182. display: flex;
  183. flex-direction: column;
  184. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  185. /* #ifndef APP-ANDROID */
  186. min-height: 100vh;
  187. /* #endif */
  188. height: 120rpx;
  189. }
  190. .download-card {
  191. background: #ffffff;
  192. border-radius: 20rpx;
  193. padding: 15rpx 15rpx;
  194. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  195. display: flex;
  196. flex-direction: column;
  197. }
  198. .title {
  199. width: 100rpx;
  200. }
  201. .inputDisabled {
  202. background-color: #dfdfdf;
  203. }
  204. </style>