web
2025-04-26 8e38cc8536cfda9b6bda8548d63778cbf5f4d634
fix:添加个人中心和重置密码
已添加1个文件
已修改6个文件
371 ■■■■ 文件已修改
src/api/login.js 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/system/user.js 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/screen/flow/report/index.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/screen/temperature/report/index.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/user/index.vue 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/userCenter.vue 248 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/login.js
@@ -25,3 +25,21 @@
        method: 'get',
    });
}
export function userDetail() {
    return {
        get: (id) => {
            return publicRequest({
                url: `/admin/user/detail/${id}`,
                method: 'get',
            });
        },
        setPsw: (data) => {
            return publicRequest({
                url: '/admin/user/changePassword',
                method: 'post',
                data
            });
        },
    }
}
src/api/system/user.js
@@ -65,5 +65,12 @@
        method: 'get',
      })
    },
    //获取已绑定管理员的角色列表
    resetPwd:(id) =>{
      return publicRequest({
        url: `/admin/user/resetPassword/${id}`,
        method: 'post',
      })
    },
  } 
}
src/router/index.js
@@ -8,6 +8,7 @@
 */
import { createWebHashHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout'
import Screen from '@/screen'
import Flow from '@/screen/flow.vue'
import Temp from '@/screen/temp.vue'
@@ -36,7 +37,16 @@
  {
    path: '/',
    hidden: true,
    redirect: '/flow'
    component: Layout,
    redirect: '/screen',
    children: [
      {
        path: 'userCenter',
        component: () => import('@/views/userCenter.vue'),
        name: 'userCenter',
        meta: { title: '个人中心', icon: 'PhUserCircleFill', affix: true }
      },
    ]
  },
  {
    path: '/login',
src/views/screen/flow/report/index.vue
@@ -7,17 +7,9 @@
const cascaderOption = { label: 'pointName', value: 'id', children: 'childrenList', checkStrictly: true, expandTrigger: 'hover', emitPath: false }; //级联选择器配置
const typeOption = ref([])
const timeOption = ref([
    { label: '小时', value: 1 },
    { label: '日', value: 2 },
    { label: '月', value: 4 },
    { label: '季度', value: 5 },
    { label: '年', value: 6 },
])
const timeVal = ref([])
const searchData = reactive({
    pointId: '',
    dateType: 2,
    createTimeRange: ''
})
const tableRef = ref(null); //表格实例
@@ -72,21 +64,6 @@
    <div class="report">
        <div class="report-tool">
            <el-cascader size="large" v-model="searchData.pointId" :options="typeOption" :show-all-levels="false" :props="cascaderOption" clearable />
            <el-select
                v-model="searchData.dateType"
                class="tool-select"
                size="large"
                placeholder="请选择"
                clearable
                style="width: 15rem"
            >
                <el-option
                    v-for="item in timeOption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
            <el-date-picker
                v-model="timeVal"
                type="datetimerange"
src/views/screen/temperature/report/index.vue
@@ -7,17 +7,9 @@
const cascaderOption = { label: 'pointName', value: 'id', children: 'childrenList', checkStrictly: true, expandTrigger: 'hover', emitPath: false }; //级联选择器配置
const typeOption = ref([])
const timeOption = ref([
    { label: '小时', value: 1 },
    { label: '日', value: 2 },
    { label: '月', value: 3 },
    { label: '季度', value: 4 },
    { label: '年', value: 5 },
])
const timeVal = ref([])
const searchData = reactive({
    pointId: '',
    dateType: 2,
    createTimeRange: ''
})
const tableRef = ref(null); //表格实例
@@ -71,21 +63,6 @@
    <div class="report">
        <div class="report-tool">
            <el-cascader size="large" v-model="searchData.pointId" :options="typeOption" :show-all-levels="false" :props="cascaderOption" clearable />
            <el-select
                v-model="searchData.dateType"
                class="tool-select"
                size="large"
                placeholder="请选择"
                clearable
                style="width: 15rem"
            >
                <el-option
                    v-for="item in timeOption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
            <el-date-picker
                v-model="timeVal"
                type="datetimerange"
src/views/system/user/index.vue
@@ -30,7 +30,8 @@
                    plain
                    icon="Plus"
                    @click="handleAdd"
                >新增</el-button>
                >新增
                </el-button>
              </el-col>
          </el-row>
          <!--表格及分页-->
@@ -51,7 +52,10 @@
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
                    <el-button v-if="scope.row.userType == 3" link type="primary" icon="Edit" @click="handleRole(scope.row)">绑定角色</el-button>
                    <el-button v-if="scope.row.userType == 3" link type="primary" icon="Edit"
                               @click="handleRole(scope.row)">绑定角色
                    </el-button>
                    <el-button link type="primary" icon="reset" @click="handeReset(scope.row)">重置密码</el-button>
                    <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
                </template>
              </el-table-column>
@@ -91,9 +95,7 @@
                        <el-form-item label="联系方式" prop="contact">
                          <el-input v-model="form.contact" placeholder="请输入联系方式" />
                      </el-form-item>
                      <el-form-item v-if="!form.id">
                          <br>
                      </el-form-item>
                <el-form-item />
                        <el-form-item label="上传头像" prop="">
                            <upload-icons @uploadData="uploadData" :imageList="form.headImg" :limit="1"></upload-icons>
                      </el-form-item>
@@ -117,7 +119,8 @@
                >
                <div class="bandCheck">
                    <el-checkbox-group v-model="roleCheckedList">
                        <el-checkbox v-for="(item,index) in roleSelectList" :key="index" :label="item.name" :value="item.id" size ="large" />
                    <el-checkbox v-for="(item,index) in roleSelectList" :key="index" :label="item.name" :value="item.id"
                                 size="large"/>
                    </el-checkbox-group>
                </div>
                <div class="handleBtn">
@@ -133,6 +136,7 @@
    import  role from "@/api/system/role";
    import  { sysDictData } from "@/api/system/dict";
    import setPostParams from "@/utils/searchParams.js";
    const { proxy } = getCurrentInstance();
    const imgBaseUrl = import.meta.env.VITE_APP_IMG_BASEURL //图片前缀
    
@@ -167,6 +171,7 @@
        email:'邮箱地址',
        createTimeView:'创建时间'
      })
    /** 获取列表 */
    async function getList(val) {
          loading.value = true;
@@ -196,6 +201,15 @@
      title.value = "修改用户";
    }
/** 重置密码 */
function handeReset(row) {
    proxy.$modal.confirm('是否确认重置"' + row.nickName + '"的密码?').then(function () {
        return user().resetPwd(row.id).then(res => {
            proxy.$modal.confirm(`重置密码成功,新密码为:${res.data}`);
        })
    })
}
    /** 删除按钮操作 */
    function handleDelete(row) {
      proxy.$modal.confirm('是否确认删除名称为"' + row.nickName + '"的数据项?').then(function() {
@@ -203,7 +217,8 @@
      }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }).catch(() => {
    });
    }
    /**
@@ -242,6 +257,7 @@
      userTypeList.value = res.data
        })
    }
    /** 提交按钮 */
    function submitForm() {
      proxy.$refs["userRef"].validate(valid => {
@@ -305,12 +321,14 @@
    }
    //绑定按钮
    const userId = ref()
    async function handleRole(row){
      open1.value = true
      userId.value = row.id
      await getUserRole()
      await getBandedRoleList(userId.value)
    }
    //获取已绑定角色列表
    async function getBandedRoleList(id){
      await user().getListRoleAdmin(id).then((res) =>{
@@ -324,6 +342,7 @@
        }
      })
    }
    //绑定请求
    async function bandListConfirm(){
      let postParam = {
@@ -338,6 +357,7 @@
        }
      })
    }
    getUserType()
    getList();
    </script>
@@ -346,8 +366,10 @@
        max-width: 100px;
        height: 50px;
    }
    .el-dialog{
        width:50vw;
        .user-form{
            display: flex;
            flex-wrap: wrap;
@@ -355,11 +377,13 @@
            align-items: center;
            margin: 20px auto;
            width: 90%;
            .el-form-item{
                width: 45%;
            }
        }
    }
    .bandCheck{
      width:100%;
      /* background-color: beige; */
@@ -368,12 +392,14 @@
      align-items: center;
      margin-bottom:100px;
    }
    .handleBtn{
      width:100%;
      /* background-color: beige; */
      display: flex;
      justify-content: center;
      align-items: center;
      .el-button{
        width:100px;
      }
src/views/userCenter.vue
对比新文件
@@ -0,0 +1,248 @@
<template>
    <div class="user-container">
        <div class="user-content">
            <div class="title">个人信息</div>
            <div class="user-form">
                <div class="item">
                    <div class="name">头像:</div>
                    <div class="image">
                        <img :src="preUrl + form.headImg" class="userImage"/>
                    </div>
                </div>
                <div class="item">
                    <div class="name">用户名:</div>
                    <div class="info">{{ form.userName }}</div>
                </div>
                <div class="item">
                    <div class="name">昵称:</div>
                    <div class="info">{{ form.nickName }}</div>
                </div>
                <div class="item">
                    <div class="name">联系方式:</div>
                    <div class="info">{{ form.contact }}</div>
                </div>
                <div class="item">
                    <div class="name">邮箱:</div>
                    <div class="info">{{ form.email }}</div>
                </div>
                <div class="item">
                    <div class="name">密码:</div>
                    <div class="info pwd">
                        ********
                        <el-button type="plain" @click="isShow = true">修改密码</el-button>
                    </div>
                </div>
            </div>
            <div class="bottom">
                <el-button type="primary" @click="loginOut">退出登录</el-button>
            </div>
            <div class="footer"></div>
        </div>
        <el-dialog v-model="isShow">
            <div class="title">修改密码</div>
            <el-form :model="pwdForm" ref="formRef" :rules="rules">
                <el-form-item prop="oldPassword" label="旧密码">
                    <el-input v-model="pwdForm.oldPassword" placeholder="请输入旧密码"></el-input>
                </el-form-item>
                <el-form-item prop="newPassword" label="新密码">
                    <el-input v-model="pwdForm.newPassword"  placeholder="请输入新密码"></el-input>
                </el-form-item>
                <el-form-item prop="confirmPassword" label="确认密码">
                    <el-input v-model="pwdForm.confirmPassword"  placeholder="再次输入新密码"></el-input>
                </el-form-item>
                <el-form-item class="handel-btn">
                    <el-button  @click="cancel()">取消</el-button>
                    <el-button type="primary"  @click="modifyPwd()">提交</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script setup>
import {userDetail} from '@/api/login'
const { proxy } = getCurrentInstance();
const form = ref({})
const preUrl = ref(import.meta.env.VITE_APP_IMG_BASEURL)
const getUserInfo = async () =>{
    let id = JSON.parse(localStorage.getItem('id'))
    await userDetail().get(id).then(res => {
        form.value = res.data
    })
}
const confirmPass =  (rule, value, callback) => {
    if (value === '') {
        callback(new Error('请再次输入密码'));
    } else if (value !== pwdForm.value.newPassword) {
        callback(new Error('两次输入密码不一致!'));
    } else {
        callback();
    }
}
//修改密码
const rules = {
    oldPassword: [
        { required: true, message: "密码不能为空", trigger: "blur" },
    ],
    newPassword: [
        {required: true, pattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W_]).{8,}$/,  message: "密码必须是8位以上的英文数字字符组合", trigger: "blur" }
    ],
    confirmPassword: [
        { required: true, validator: confirmPass, message: "两次密码不一致", trigger: "blur" }
    ]
}
const formRef = ref()
const isShow = ref(false)
const pwdForm = ref({
    oldPassword:'',
    newPassword:'',
    confirmPassword:'',
})
const modifyPwd = () =>{
    formRef.value.validate(async (valid) => {
        if(valid){
            const data = {
                oldPassword: pwdForm.value.oldPassword,
                newPassword: pwdForm.value.newPassword
            }
            await userDetail().setPsw(data).then(res => {
                if(res.code == 200){
                    proxy.$modal.msgSuccess("修改成功");
                }
            })
        }
    })
}
const cancel = () =>{
    isShow.value = false
    pwdForm.value = {}
}
onMounted(() =>{
    getUserInfo()
})
</script>
<style lang="scss" scoped>
.user-container{
    width: 100%;
    padding: 1% 12%;
    .user-content{
        width: 100%;
        background: rgba(242, 246, 248, 0.4);
        border-radius: 20px;
        .title{
            width: 100%;
            height:80px;
            background: rgba(112, 184, 225, 0.13);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 30px;
            color: #262627;
            border-top-left-radius: 20px;
            border-top-right-radius: 20px;
        }
        .user-form{
            width: 100%;
            height:550px;
            padding: 10px 80px;
            .item{
                width: 100%;
                height: 16%;
                display: flex;
                justify-content:flex-start;
                align-items:center;
                margin-left: 10%;
                .name{
                    width:90px;
                    font-size: 20px;
                    color: #626268;
                    font-weight: bold;
                    margin-right: 20px;
                }
                .info{
                    width: 70%;
                    height: 35%;
                    display: flex;
                    align-items:center;
                    border-bottom: 1px solid rgba(29, 33, 41, 0.27);
                    font-size: 18px;
                    color: rgba(66, 66, 67, 0.98);
                    font-weight: bold;
                }
                .pwd{
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    .el-button{
                        margin-bottom: 10px;
                    }
                }
            }
        }
        .bottom{
            width: 100%;
            height:80px;
            //background: rgba(112, 184, 225, 0.13);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 30px;
            color: #262627;
        }
        .footer{
            width: 100%;
            height:100px;
            background: rgba(112, 184, 225, 0.13);
            border-bottom-left-radius: 20px;
            border-bottom-right-radius: 20px;
        }
    }
    :deep(.el-dialog){
        width: 40%;
        height:40vh;
        padding: 10px 200px;
        .title{
            width: 100%;
            height: 50px;
            display: flex;
            justify-content:center;
            align-items: center;
            font-weight: bold;
            font-size: 20px;
            margin-bottom: 50px;
        }
        .el-form{
            .el-form-item{
                margin-bottom: 30px;
            }
            .handel-btn{
                width: 50%;
                margin: 0 auto;
                .el-button{
                    width: 40%;
                    height: 35px;
                    display: flex;
                    justify-content:center;
                    align-items: center;
                    font-size: 18px;
                    margin: 20px auto;
                    letter-spacing: 6px;
                }
            }
        }
    }
}
.image{
    border:1px solid rgba(112, 184, 225, 0.32);
    border-radius: 10px;
    padding: 5px;
}
.userImage{
    width: 100px;
    max-height:100px;
}
</style>