| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <template>
- <div class="app-content">
- <!-- tabs -->
- <div class="tabs-wrap">
- <button
- class="admin-button-com"
- :class="[tabIndex == 1? 'blue' : '']"
- @click="changeTab(1)"
- >密码设置</button>
- <button
- class="admin-button-com"
- :class="[tabIndex == 2? 'blue' : '']"
- @click="changeTab(2)"
- >确认密码设置</button>
- </div>
- <!-- 输入框 - block -->
- <form @submit="formSubmit">
- <div class="input-line-wrap">
- <tui-list-cell class="line-cell">
- <div class="tui-title">帐号</div>
- <div class="tui-title">{{selfInfo.id}}</div>
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false" v-if="isOldPass">
- <div class="tui-title">旧密码</div>
- <input
- placeholder-class="phcolor"
- v-model="form.old"
- class="tui-input"
- name="old"
- placeholder="请输入旧密码"
- maxlength="50"
- type="password"
- />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <div class="tui-title">密码</div>
- <input
- placeholder-class="phcolor"
- v-model="form.new"
- class="tui-input"
- name="new"
- placeholder="请输入确认密码"
- maxlength="50"
- type="password"
- />
- </tui-list-cell>
- <tui-list-cell class="line-cell" :hover="false">
- <div class="tui-title">确认密码</div>
- <input
- placeholder-class="phcolor"
- v-model="form.confirm"
- class="tui-input"
- name="confirm"
- placeholder="请输入确认密码"
- maxlength="50"
- type="password"
- />
- </tui-list-cell>
- <div class="btn-wrap">
- <button class="admin-button-com blue big" formType="submit">提交</button>
- </div>
- </div>
- </form>
- </div>
- </template>
- <script>
- import { mapGetters } from "vuex";
- import TuiListCell from "@/components/plugin/list-cell";
- const form = require("@/utils/formValidation.js");
- import { getSelfInfo } from "@/utils/auth";
- import { updatePassword, updateConfirmPassword } from "@/api/login";
- export default {
- name: "password-setting",
- components: {
- TuiListCell
- },
- data() {
- return {
- tabIndex: 1,
- form: {
- old: "",
- new: "",
- confirm: ""
- },
- old: [
- {
- name: "old",
- rule: ["required"],
- msg: ["请输入旧密码"]
- }
- ],
- rules: [
- {
- name: "new",
- rule: ["required"],
- msg: ["请输入新密码"]
- },
- {
- name: "confirm",
- rule: ["required"],
- msg: ["请输入确认密码"]
- }
- ]
- };
- },
- computed: {
- ...mapGetters({ selfInfo: "getSelfInfo" }),
- isOldPass() {
- let status = this.selfInfo
- ? this.tabIndex == 1
- ? this.selfInfo.password
- : this.selfInfo.confirmPassword
- : false;
- return !!status;
- }
- },
- onLoad() {
- getSelfInfo().then(res => {});
- },
- methods: {
- changeTab(index) {
- this.tabIndex = index;
- this.form = {
- old: "",
- new: "",
- confirm: ""
- };
- },
- confirmFn() {
- if (!this.isOldPass) {
- delete this.form.old;
- }
- let hostFn = this.tabIndex == 1 ? updatePassword : updateConfirmPassword;
- hostFn(this.form).then(res => {
- this.$msg("修改成功!");
- this.$util.pageTo({
- url: "/admin/home/workbench",
- type: 4
- });
- });
- },
- // 表单验证
- formSubmit(e) {
- // 表单规则
- let rules = this.isOldPass ? [...this.old, ...this.rules] : this.rules;
- // 进行表单检查
- let formData = e.detail.value;
- let checkRes = form.validation(formData, rules);
- // 验证通过!
- if (!checkRes) {
- this.confirmFn();
- } else {
- this.$msg(checkRes);
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .tabs-wrap {
- width: calc(100% - 60upx);
- padding: 20upx 30upx;
- .admin-button-com {
- width: 50%;
- padding-top: 16upx;
- padding-bottom: 16upx;
- &:first-child {
- border-top-right-radius: 0;
- border-bottom-right-radius: 0;
- }
- &:last-child {
- border-top-left-radius: 0;
- border-bottom-left-radius: 0;
- }
- }
- }
- // 按钮
- .btn-wrap {
- width: calc(100% - 60upx);
- margin: 60upx 30upx 0;
- .admin-button-com {
- width: 100%;
- margin: 0 auto;
- }
- }
- </style>
|