edit.uvue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class=" container my-page">
  3. <view class=" example">
  4. <form>
  5. <view class="uni-form-item uni-row">
  6. <view class="title">用户昵称</view>
  7. <input :class="'uni-input '+nickName"
  8. name="nickName"
  9. :value="user.nickName"
  10. placeholder="请输入昵称"
  11. @focus="inputFocus('nickName')"
  12. @blur="inputBlur('nickName')"
  13. @input="inputNick"
  14. />
  15. </view>
  16. <view class="uni-form-item uni-row">
  17. <view class="title">手机号码</view>
  18. <input :class="'uni-input '+phonenumber"
  19. name="phonenumber"
  20. :value="user.phonenumber"
  21. placeholder="请输入手机号码"
  22. @focus="inputFocus('phonenumber')"
  23. @blur="inputBlur('phonenumber')"
  24. @input="inputPhone"
  25. />
  26. <!-- <uni-icons
  27. v-if="!user.nickName"
  28. class="content-clear-icon"
  29. type="clear"
  30. :size="24"
  31. :color="focusShow ? '#2979ff' : '#c0c4cc'"
  32. @click="onClear('nickName')"
  33. ></uni-icons> -->
  34. </view>
  35. <view class="uni-form-item uni-row">
  36. <view class="title">邮箱</view>
  37. <input :class="'uni-input '+email"
  38. name="email"
  39. :value="user.email"
  40. placeholder="请输入姓名"
  41. @focus="inputFocus('email')"
  42. @blur="inputBlur('email')"
  43. @input="inputEmail"
  44. />
  45. <!-- <uni-icons
  46. v-if="!user.nickName"
  47. class="content-clear-icon"
  48. type="clear"
  49. :size="24"
  50. :color="focusShow ? '#2979ff' : '#c0c4cc'"
  51. @click="onClear('nickName')"
  52. ></uni-icons> -->
  53. </view>
  54. <view class="uni-form-item uni-row">
  55. <view class="title">性别</view>
  56. <radio-group name="sex" class="uni-row" @change="changeSex">
  57. <view class="group-item uni-row" v-for="(item,index) in sexs">
  58. <radio class="my-radio" :value="item.value" :checked="item.value==user.sex" />
  59. <text class="my-text">{{item.text}}</text>
  60. </view>
  61. </radio-group>
  62. </view>
  63. </form>
  64. <button type="primary" @click="submit">提交</button>
  65. </view>
  66. </view>
  67. </template>
  68. <script lang="uts">
  69. import { getUserProfile } from "@/api/system/user"
  70. import { updateUserProfile } from "@/api/system/user"
  71. export default {
  72. data() {
  73. type Sex={
  74. text:string,
  75. value:string
  76. }
  77. return {
  78. nickName:'',
  79. phonenumber:'',
  80. email:'',
  81. user: {
  82. nickName: "" as string,
  83. phonenumber: "" as string,
  84. email: "" as string,
  85. sex: "0" as string
  86. } as UTSJSONObject,
  87. sexs: [{
  88. text: '男',
  89. value: "0"
  90. }, {
  91. text: '女',
  92. value: "1"
  93. }] as Sex[],
  94. }
  95. },
  96. onLoad() {
  97. this.getUser()
  98. },
  99. methods: {
  100. changeSex(event: UniRadioGroupChangeEvent){
  101. this.user.sex=event.detail.value as string
  102. },
  103. inputFocus(tag:string){
  104. this.$data[tag]="my-focus"
  105. },
  106. inputBlur(tag:string){
  107. this.$data[tag]="my-blur"
  108. },
  109. inputEmail(event:UniInputEvent){
  110. this.user.email=event.detail.value
  111. },
  112. inputNick(event:UniInputEvent){
  113. this.user.nickName=event.detail.value
  114. },
  115. inputPhone(event:UniInputEvent){
  116. this.user.phonenumber=event.detail.value
  117. },
  118. getUser() {
  119. getUserProfile().then((response:any) => {
  120. this.user = response.data
  121. })
  122. },
  123. submit(ref) {
  124. if(!this.user.nickName){
  125. uni.showToast({
  126. title:"用户昵称不能为空",
  127. icon:"error"
  128. })
  129. return
  130. }
  131. if(!this.user.phonenumber){
  132. uni.showToast({
  133. title:"手机号码不能为空",
  134. icon:"error"
  135. })
  136. return
  137. }else if(!/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(this.user.phonenumber)){
  138. uni.showToast({
  139. title:"请输入正确的手机号码",
  140. icon:"error"
  141. })
  142. return
  143. }
  144. if(!this.user.email){
  145. uni.showToast({
  146. title:"邮箱地址不能为空",
  147. icon:"error"
  148. })
  149. return
  150. }else if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.user.email)){
  151. uni.showToast({
  152. title:"请输入正确的邮箱地址",
  153. icon:"error"
  154. })
  155. return
  156. }
  157. updateUserProfile(this.user).then((response) => {
  158. uni.showToast({
  159. title: '修改成功',
  160. icon: 'success'
  161. });
  162. });
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .my-page {
  169. background-color: #ffffff;
  170. width: 100%;
  171. height: 100%;
  172. }
  173. .example {
  174. padding: 15px;
  175. background-color: #fff;
  176. }
  177. .segmented-control {
  178. margin-bottom: 15px;
  179. }
  180. .button-group {
  181. margin-top: 15px;
  182. display: flex;
  183. justify-content: space-around;
  184. }
  185. .form-item {
  186. display: flex;
  187. align-items: center;
  188. flex: 1;
  189. }
  190. .button {
  191. display: flex;
  192. align-items: center;
  193. height: 35px;
  194. line-height: 35px;
  195. margin-left: 10px;
  196. }
  197. </style>