edit.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="container">
  3. <view class="example">
  4. <uni-forms ref="form" :model="user" labelWidth="80px">
  5. <uni-forms-item label="用户昵称" name="nickName">
  6. <uni-easyinput v-model="user.nickName" placeholder="请输入昵称" />
  7. </uni-forms-item>
  8. <uni-forms-item label="手机号码" name="phonenumber">
  9. <uni-easyinput v-model="user.phonenumber" placeholder="请输入手机号码" />
  10. </uni-forms-item>
  11. <uni-forms-item label="邮箱" name="email">
  12. <uni-easyinput v-model="user.email" placeholder="请输入邮箱" />
  13. </uni-forms-item>
  14. <uni-forms-item label="性别" name="sex" required>
  15. <uni-data-checkbox v-model="user.sex" :localdata="sexs" />
  16. </uni-forms-item>
  17. </uni-forms>
  18. <button type="primary" @click="submit">提交</button>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import { getUserProfile } from "@/api/system/user"
  24. import { updateUserProfile } from "@/api/system/user"
  25. export default {
  26. data() {
  27. return {
  28. user: {
  29. nickName: "",
  30. phonenumber: "",
  31. email: "",
  32. sex: ""
  33. },
  34. sexs: [{
  35. text: '男',
  36. value: "0"
  37. }, {
  38. text: '女',
  39. value: "1"
  40. }],
  41. rules: {
  42. nickName: {
  43. rules: [{
  44. required: true,
  45. errorMessage: '用户昵称不能为空'
  46. }]
  47. },
  48. phonenumber: {
  49. rules: [{
  50. required: true,
  51. errorMessage: '手机号码不能为空'
  52. }, {
  53. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  54. errorMessage: '请输入正确的手机号码'
  55. }]
  56. },
  57. email: {
  58. rules: [{
  59. required: true,
  60. errorMessage: '邮箱地址不能为空'
  61. }, {
  62. format: 'email',
  63. errorMessage: '请输入正确的邮箱地址'
  64. }]
  65. }
  66. }
  67. }
  68. },
  69. onLoad() {
  70. this.getUser()
  71. },
  72. onReady() {
  73. this.$refs.form.setRules(this.rules)
  74. },
  75. methods: {
  76. getUser() {
  77. getUserProfile().then(response => {
  78. this.user = response.data
  79. })
  80. },
  81. submit(ref) {
  82. this.$refs.form.validate().then(res => {
  83. updateUserProfile(this.user).then(response => {
  84. this.$modal.msgSuccess("修改成功")
  85. })
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. page {
  93. background-color: #ffffff;
  94. }
  95. .example {
  96. padding: 15px;
  97. background-color: #fff;
  98. }
  99. .segmented-control {
  100. margin-bottom: 15px;
  101. }
  102. .button-group {
  103. margin-top: 15px;
  104. display: flex;
  105. justify-content: space-around;
  106. }
  107. .form-item {
  108. display: flex;
  109. align-items: center;
  110. flex: 1;
  111. }
  112. .button {
  113. display: flex;
  114. align-items: center;
  115. height: 35px;
  116. line-height: 35px;
  117. margin-left: 10px;
  118. }
  119. </style>