zuozhengqing
2024-02-05 5e9e244eab03d1b24fe6dae3fa7052cf068e5a52
crm添加修改密码
3个文件已修改
2个文件已添加
247 ■■■■■ 已修改文件
src/api/admin/user.js 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/common/untils/request.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/layout/components/appHeader/components/updatePassWord.vue 186 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/layout/components/appHeader/index.vue 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vue.config.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/admin/user.js
New file
@@ -0,0 +1,20 @@
import request from "@/common/untils/request.js"
// 重置密码
export function initPassword(data) {
  return request({
    url: "/api/user/initPassword",
    method: "post",
    data,
  });
}
// 设置新密码
export function modifiedPwd(data) {
  return request({
    url: "/api/user/modifiedPwd",
    method: "post",
    data,
  });
}
src/common/untils/request.js
@@ -33,7 +33,7 @@
        prod:`//${window.location.hostname}:9080`,
        test:`//192.168.20.119:9080`,
        // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
        dev: `//192.168.20.158:8080`
        dev: `//192.168.8.108:8080`
    }
    return loginPathMap[environmentType()]
src/components/layout/components/appHeader/components/updatePassWord.vue
New file
@@ -0,0 +1,186 @@
<template>
  <div>
    <el-dialog
      title="修改密码"
      :visible.sync="editConfig.dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form :label-position="labelPosition" :model="ruleForm"  :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="旧密码:" prop="oldPass">
          <el-input type="password" clearable v-model="ruleForm.oldPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="新密码:" prop="pass">
          <el-input type="password" clearable v-model="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码:" prop="checkPass">
          <el-input type="password"  clearable v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')" style="margin-bottom:20px;">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import Cookies from 'js-cookie';
import { modifiedPwd } from "@/api/admin/user";
export default {
  props: {
    editCommonConfig: {
      type: Object,
      default: () => {
        return {
          dialogVisible:false,
          userId:"",
        };
      },
    },
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入旧密码'));
      }else{
        callback();
      }
    };
    var validatePass1 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入新密码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      editConfig:this.editCommonConfig,
      // dialogVisible: false
      ruleForm: {
        oldPass:'',
        pass: '',
        checkPass: '',
      },
      rules: {
        oldPass: [
          { validator: validatePass, trigger: 'blur', required: true, }
        ],
        pass: [
          { validator: validatePass1, trigger: 'blur', required: true, }
        ],
        checkPass: [
          { validator: validatePass2, trigger: 'blur', required: true, }
        ],
      },
      labelPosition:"left",
      userId : '',
    };
  },
  created(){
  },
  computed: {
  },
  created() {
  },
  mounted() {
  },
  watch: {
  },
  methods: {
    //
    environmentType(){
      let type
      if (location.href.includes('192.168.20.119')) {
        type = 'test'
      } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
        type = 'dev'
      } else {
        type = 'prod'
      }
      return type
    },
    //
    getApsPage(){
      // 首页部署在各个环境的端口
      const loginPathMap = {
        prod:`//${window.location.hostname}:9080`,
        test:`//192.168.20.119:9080`,
        // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
        dev: `//192.168.8.108:8080`
      }
      return loginPathMap[this.environmentType()]
    },
    handleClose(done){
      done();
    },
    modifiedPwd(params){
      modifiedPwd(params).then((res)=>{
        if(res.code==200){
          this.editConfig.dialogVisible=false
          alert("密码修改成功,请重新登录!")
          window.location = this.getApsPage()+'/login'
        }
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm,"看看表单")
          this.modifiedPwd({
            userId:this.editConfig.userId,
            oldPwd:this.ruleForm.oldPass,
            newPwd:this.ruleForm.pass,
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
  components: {
  },
};
</script>
<style scoped lang="scss">
.el-form{
  margin-top:20px;
}
::v-deep {
  .el-form-item__content{
    display: flex;
    flex-direction: row-reverse;
  }
  .el-dialog__header{
    .el-dialog__title{
      font-size:18px;
    }
  }
  .el-form{
    margin:20px;
  }
}
</style>
src/components/layout/components/appHeader/index.vue
@@ -4,29 +4,54 @@
    <div class="header-user-info">
      <div class="avatar"><el-avatar icon="el-icon-user-solid"></el-avatar></div>
      <el-dropdown @command="handleCommand">
        <div class="el-dropdown-link">{{ username }}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></div>
        <div class="el-dropdown-link">你好  {{ username }}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="logout">退出</el-dropdown-item>
          <el-dropdown-item @click.native="updatePwd">
            <d2-icon name="unlock" class="d2-mr-5" />
            修改密码
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <UpdatePassWord :editCommonConfig="editConfig"></UpdatePassWord>
    </div>
  </div>
</template>
<script>
import Cookies from "js-cookie"
import UpdatePassWord from "./components/updatePassWord"
export default {
  name: "SalesLead",
  name: "SalesLeads",
  props: {
    headerTitle: String
  },
  components:{
    UpdatePassWord,
  },
  data() {
    return {
      username: ""
      username: "",
      editConfig:{
        dialogVisible:false,
        userId:"",
      }
    }
  },
  created(){
    const userObj = Cookies.get('userObj');
    console.log(userObj,"看看")
    if (userObj) {
      let userInfo = JSON.parse(userObj);
      this.editConfig.userId=userInfo.id
      this.username=userInfo.nickName
    } else {
      console.log('Object not found in cookie');
    }
  },
  mounted() {
    this.username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1")
    // this.username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1")
  },
  methods: {
    environmentType() {
@@ -52,7 +77,6 @@
      return loginPathMap[this.environmentType()]
    },
    handleCommand(command) {
      console.log(command)
      if (command === "logout") {
        // this.$router.push({ path: "/login" })
        document.cookie = "cookieName=; path=/;"
@@ -77,6 +101,9 @@
            })
          })
      }
    },
    updatePwd(){
      this.editConfig.dialogVisible=true
    }
  }
}
vue.config.js
@@ -21,7 +21,7 @@
        changeOrigin: true
      },
      "/api": {
        target: "http://192.168.20.119:8002", // http://192.168.20.119:8002 http://fai365.com:30150/
        target: "http://192.168.20.119:8001", // http://192.168.20.119:8002 http://fai365.com:30150/
        // 建道本地环境
        // target: "http://192.168.20.118:8002",
        ws: true,