password.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="app-content">
  3. <!-- tabs -->
  4. <div class="tabs-wrap">
  5. <button
  6. class="admin-button-com"
  7. :class="[tabIndex == 1? 'blue' : '']"
  8. @click="changeTab(1)"
  9. >密码设置</button>
  10. <button
  11. class="admin-button-com"
  12. :class="[tabIndex == 2? 'blue' : '']"
  13. @click="changeTab(2)"
  14. >确认密码设置</button>
  15. </div>
  16. <!-- 输入框 - block -->
  17. <form @submit="formSubmit">
  18. <div class="input-line-wrap">
  19. <tui-list-cell class="line-cell">
  20. <div class="tui-title">帐号</div>
  21. <div class="tui-title">{{selfInfo.id}}</div>
  22. </tui-list-cell>
  23. <tui-list-cell class="line-cell" :hover="false" v-if="isOldPass">
  24. <div class="tui-title">旧密码</div>
  25. <input
  26. placeholder-class="phcolor"
  27. v-model="form.old"
  28. class="tui-input"
  29. name="old"
  30. placeholder="请输入旧密码"
  31. maxlength="50"
  32. type="password"
  33. />
  34. </tui-list-cell>
  35. <tui-list-cell class="line-cell" :hover="false">
  36. <div class="tui-title">密码</div>
  37. <input
  38. placeholder-class="phcolor"
  39. v-model="form.new"
  40. class="tui-input"
  41. name="new"
  42. placeholder="请输入确认密码"
  43. maxlength="50"
  44. type="password"
  45. />
  46. </tui-list-cell>
  47. <tui-list-cell class="line-cell" :hover="false">
  48. <div class="tui-title">确认密码</div>
  49. <input
  50. placeholder-class="phcolor"
  51. v-model="form.confirm"
  52. class="tui-input"
  53. name="confirm"
  54. placeholder="请输入确认密码"
  55. maxlength="50"
  56. type="password"
  57. />
  58. </tui-list-cell>
  59. <div class="btn-wrap">
  60. <button class="admin-button-com blue big" formType="submit">提交</button>
  61. </div>
  62. </div>
  63. </form>
  64. </div>
  65. </template>
  66. <script>
  67. import { mapGetters } from "vuex";
  68. import TuiListCell from "@/components/plugin/list-cell";
  69. const form = require("@/utils/formValidation.js");
  70. import { getSelfInfo } from "@/utils/auth";
  71. import { updatePassword, updateConfirmPassword } from "@/api/login";
  72. export default {
  73. name: "password-setting",
  74. components: {
  75. TuiListCell
  76. },
  77. data() {
  78. return {
  79. tabIndex: 1,
  80. form: {
  81. old: "",
  82. new: "",
  83. confirm: ""
  84. },
  85. old: [
  86. {
  87. name: "old",
  88. rule: ["required"],
  89. msg: ["请输入旧密码"]
  90. }
  91. ],
  92. rules: [
  93. {
  94. name: "new",
  95. rule: ["required"],
  96. msg: ["请输入新密码"]
  97. },
  98. {
  99. name: "confirm",
  100. rule: ["required"],
  101. msg: ["请输入确认密码"]
  102. }
  103. ]
  104. };
  105. },
  106. computed: {
  107. ...mapGetters({ selfInfo: "getSelfInfo" }),
  108. isOldPass() {
  109. let status = this.selfInfo
  110. ? this.tabIndex == 1
  111. ? this.selfInfo.password
  112. : this.selfInfo.confirmPassword
  113. : false;
  114. return !!status;
  115. }
  116. },
  117. onLoad() {
  118. getSelfInfo().then(res => {});
  119. },
  120. methods: {
  121. changeTab(index) {
  122. this.tabIndex = index;
  123. this.form = {
  124. old: "",
  125. new: "",
  126. confirm: ""
  127. };
  128. },
  129. confirmFn() {
  130. if (!this.isOldPass) {
  131. delete this.form.old;
  132. }
  133. let hostFn = this.tabIndex == 1 ? updatePassword : updateConfirmPassword;
  134. hostFn(this.form).then(res => {
  135. this.$msg("修改成功!");
  136. this.$util.pageTo({
  137. url: "/admin/home/workbench",
  138. type: 4
  139. });
  140. });
  141. },
  142. // 表单验证
  143. formSubmit(e) {
  144. // 表单规则
  145. let rules = this.isOldPass ? [...this.old, ...this.rules] : this.rules;
  146. // 进行表单检查
  147. let formData = e.detail.value;
  148. let checkRes = form.validation(formData, rules);
  149. // 验证通过!
  150. if (!checkRes) {
  151. this.confirmFn();
  152. } else {
  153. this.$msg(checkRes);
  154. }
  155. }
  156. }
  157. };
  158. </script>
  159. <style lang="scss" scoped>
  160. .tabs-wrap {
  161. width: calc(100% - 60upx);
  162. padding: 20upx 30upx;
  163. .admin-button-com {
  164. width: 50%;
  165. padding-top: 16upx;
  166. padding-bottom: 16upx;
  167. &:first-child {
  168. border-top-right-radius: 0;
  169. border-bottom-right-radius: 0;
  170. }
  171. &:last-child {
  172. border-top-left-radius: 0;
  173. border-bottom-left-radius: 0;
  174. }
  175. }
  176. }
  177. // 按钮
  178. .btn-wrap {
  179. width: calc(100% - 60upx);
  180. margin: 60upx 30upx 0;
  181. .admin-button-com {
  182. width: 100%;
  183. margin: 0 auto;
  184. }
  185. }
  186. </style>