edit.vue 3.0 KB

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