Blame view

code/finance_web/src/components/user.vue 8.61 KB
谢明辉 committed
1
<template>
a  
谢明辉 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  <div id="user_wrapper">
    <el-card class="box-card" id="user" shadow="hover" style="width:30%;">
      <div slot="header" style="text-align:center" class="clearfix">
        <span style="font-size:24px;color:#eff0dc">修改密码</span>
      </div>

      <el-form ref="password_form" :model="password_form" :rules="password_form_rules" label-width="60px" label-position="top">
        <el-form-item prop="odd_password">
          <el-input :type="odd_password_type" v-model="password_form.odd_password" auto-complete="off">
            <template slot="prepend">原密码</template>
            <el-button class="append_button" slot="append" :icon="odd_password_view" @click="show_odd_password"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="new_password">
          <el-input :type="new_password_type" v-model="password_form.new_password" auto-complete="off">
            <template slot="prepend">新密码</template>
            <el-button class="append_button" slot="append" :icon="new_password_view" @click="show_new_password"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="check_password">
          <el-input :type="new_password_type" v-model="password_form.check_password" auto-complete="off">
            <template slot="prepend">新密码</template>
            <el-button class="append_button" slot="append" :icon="new_password_view" @click="show_new_password"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary" @click="submitForm('password_form')">提交</el-button>
            <el-button type="warning" @click="resetForm('password_form')">重置</el-button>
          </el-button-group>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card" id="user" shadow="hover" style="width:30%;">
      <div slot="header" style="text-align:center" class="clearfix">
        <span style="font-size:24px;color:#eff0dc">主题颜色</span>
      </div>
      <el-radio-group v-model="color" @change="change_color">
        <el-row style="padding-bottom:1px">
          <el-radio-button label="天空蓝"></el-radio-button>
          <el-radio-button label="梦幻紫"></el-radio-button>
          <el-radio-button label="活力橙"></el-radio-button>
        </el-row>
        <el-row>
          <el-radio-button label="柠檬绿"></el-radio-button>
          <el-radio-button label="灰灰灰"></el-radio-button>
          <el-radio-button label="小清新"></el-radio-button>
        </el-row>
      </el-radio-group>
    </el-card>
  </div>
谢明辉 committed
53 54 55 56

</template>

<script>
a  
谢明辉 committed
57 58 59 60
  export default {
    name: "user",
    data() {
      return {
a  
谢明辉 committed
61
        color: "天空蓝",
a  
谢明辉 committed
62 63 64 65 66 67 68 69 70 71 72
        new_password_type: "password",
        odd_password_type: "password",
        new_password_view: "icon i-password-not-view",
        odd_password_view: "icon i-password-not-view",
        rtoken: "",
        user_unid: "",
        auth_base_url: this.$disparch_data.auth_base_url,
        password_form: {
          odd_password: "",
          new_password: "",
          check_password: ""
谢明辉 committed
73
        },
a  
谢明辉 committed
74 75
        password_form_rules: {
          odd_password: {
谢明辉 committed
76
            required: true,
a  
谢明辉 committed
77
            message: "请填写旧密码",
谢明辉 committed
78 79
            trigger: "blur"
          },
a  
谢明辉 committed
80 81 82 83 84
          new_password: [
            {
              pattern: /^[A-Za-z0-9\x20-\x7f]{6,16}$/,
              message: "密码至少6位,至多16位",
              trigger: "blur"
谢明辉 committed
85
            },
a  
谢明辉 committed
86 87 88 89
            {
              required: true,
              message: "必须填写新密码",
              trigger: "blur"
谢明辉 committed
90
            },
a  
谢明辉 committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
            {
              validator: (rule, value, callback) => {
                if (value == this.password_form.odd_password) {
                  callback(new Error("新密码不能和旧密码相同"));
                } else callback();
              },
              trigger: "blur"
            }
          ],
          check_password: [
            {
              pattern: /^[A-Za-z0-9\x20-\x7f]{6,16}$/,
              message: "密码至少6位,至多16位",
              trigger: "blur"
            },
            {
              required: true,
              message: "必须填写新密码",
              trigger: "blur"
            },
            {
              validator: (rule, value, callback) => {
                if (value != this.password_form.new_password) {
                  callback(new Error("两次输入不一致"));
                } else callback();
              },
              trigger: "blur"
            }
          ]
        }
      };
    },
    methods: {
a  
谢明辉 committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
      change_color() {
        var backgroundColor = "none";
        var backgroundImage = "none";
        switch (this.color) {
          case "天空蓝":
            backgroundColor = "lightblue";
            break;
          case "梦幻紫":
            backgroundColor = "#8ec5fc";
            backgroundImage = "linear-gradient(225deg, #8ec5fc 0%, #e0c3fc 100%)";
            break;
          case "活力橙":
            backgroundColor = "#FBAB7E";
            backgroundImage = "linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)";
            break;
          case "柠檬绿":
            backgroundColor = "#F4D03F";
            backgroundImage = "linear-gradient(132deg, #F4D03F 0%, #16A085 100%)";
            break;
          case "灰灰灰":
            backgroundColor = "#f0f0f0";
            break;
          case "小清新":
            backgroundColor = "#FFDEE9";
            backgroundImage = "linear-gradient(0deg, #FFDEE9 0%, #B5FFFC 100%)";
            break;
        }
        let main = document.getElementsByClassName("el-main")[0];
        main.style["background-color"] = backgroundColor;
        main.style.backgroundImage = backgroundImage;
        localStorage.setItem("color", this.color);
        this.$router.go(0)
      },

a  
谢明辉 committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
      show_odd_password() {
        if (this.odd_password_type == "password") {
          this.odd_password_type = "text";
          this.odd_password_view = "icon i-password-view";
        } else {
          this.odd_password_type = "password";
          this.odd_password_view = "icon i-password-not-view";
        }
      },
      show_new_password() {
        if (this.new_password_type == "password") {
          this.new_password_type = "text";
          this.new_password_view = "icon i-password-view";
        } else {
          this.new_password_type = "password";
          this.new_password_view = "icon i-password-not-view";
        }
      },
      submitForm(form) {
        this.$refs[form].validate(valid => {
          if (valid) {
            this.$Axios({
              method: "post",
              url: this.auth_base_url + "users/" + this.user_unid + "/password",
              headers: { authorization: this.rtoken },
              data: {
                old_pwd: this.password_form.odd_password,
                new_pwd: this.password_form.new_password
              }
            })
              .then(response => {
                if (response.data.user_unid) {
                  this.$message({
                    type: "success",
                    message: "修改成功"
                  });
                  this.resetForm("password_form");
                }
              })
              .catch(err => {
                this.$message.error("修改失败");
                this.resetForm("password_form");
              });
谢明辉 committed
201
          }
a  
谢明辉 committed
202 203 204 205
        });
      },
      resetForm(form) {
        this.$refs[form].resetFields();
谢明辉 committed
206 207
      }
    },
a  
谢明辉 committed
208 209 210
    created() {
      if (!sessionStorage.getItem("user_unid")) {
        this.$router.push("/");
谢明辉 committed
211
      } else {
a  
谢明辉 committed
212 213
        this.rtoken = sessionStorage.getItem("rtoken");
        this.user_unid = sessionStorage.getItem("user_unid");
谢明辉 committed
214
      }
a  
谢明辉 committed
215 216 217 218

      if (localStorage.getItem("color")) {
        this.color = localStorage.getItem("color");
      }
谢明辉 committed
219
    }
a  
谢明辉 committed
220
  };
谢明辉 committed
221 222 223 224
</script>


<style scoped>
a  
谢明辉 committed
225 226 227 228
#user_wrapper {
  width: 100%;
  height: 100%;
}
a  
谢明辉 committed
229 230 231
#user >>> label {
  color: black;
}
a  
谢明辉 committed
232 233 234 235 236
#user_wrapper >>> .el-card {
  /* float: left; */
  /* display: inline-block; */
  background-color: rgba(0, 0, 0, 0);
}
a  
谢明辉 committed
237
#user >>> .el-card__body {
a  
谢明辉 committed
238
  background-color: rgba(0, 0, 0, 0);
a  
谢明辉 committed
239 240 241 242
}
#user >>> input {
  border-color: black;
  color: black;
a  
谢明辉 committed
243
  background-color: rgba(0, 0, 0, 0);
a  
谢明辉 committed
244 245 246 247 248 249 250
}
#user >>> .el-card__header {
  background-color: #34352c;
}
#user >>> .el-input-group__prepend {
  border-color: black;
  color: black;
a  
谢明辉 committed
251
  /* background-color: lightgray; */
a  
谢明辉 committed
252
  background-color: rgba(0, 0, 0, 0);
a  
谢明辉 committed
253 254 255 256
}
#user >>> .el-input-group__append {
  color: black;
  border-color: black;
a  
谢明辉 committed
257 258 259 260 261
  background-color: rgba(0, 0, 0, 0);
}
#user >>> .el-radio-button__inner {
  border-color: black;
  background-color: rgba(0, 0, 0, 0);
a  
谢明辉 committed
262
}
谢明辉 committed
263 264
</style>