| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- <template>
- <div
- :class="[
- 'login-wrapper',
- ['', 'login-form-right', 'login-form-left'][direction]
- ]"
- >
- <el-form
- ref="form"
- size="large"
- :model="form"
- :rules="rules"
- class="login-form ele-bg-white"
- @keyup.enter.native="submit"
- >
- <h4>{{ $t('login.title') }}</h4>
- <el-form-item prop="loginName">
- <el-input
- clearable
- v-model="form.loginName"
- prefix-icon="el-icon-user"
- placeholder="请输入登录账号"
- />
- </el-form-item>
- <el-form-item prop="loginPwd">
- <el-input
- show-password
- v-model="form.loginPwd"
- prefix-icon="el-icon-lock"
- placeholder="请输入登录密码"
- />
- </el-form-item>
- <el-form-item prop="captcha">
- <div class="login-input-group">
- <el-input
- clearable
- v-model="form.captcha"
- prefix-icon="el-icon-_vercode"
- :placeholder="$t('login.code')"
- />
- <img
- alt=""
- :src="captcha"
- class="login-captcha"
- @click="changeCaptcha"
- />
- </div>
- </el-form-item>
- <div class="el-form-item">
- <el-checkbox v-model="form.remember">
- {{ $t('login.remember') }}
- </el-checkbox>
- <el-link
- type="primary"
- :underline="false"
- class="ele-pull-right"
- @click="$router.push('/forget')"
- >
- 忘记密码
- </el-link>
- </div>
- <div class="el-form-item">
- <el-button
- size="large"
- type="primary"
- class="login-btn"
- :loading="loading"
- @click="submit"
- >
- {{ loading ? $t('login.loading') : $t('login.login') }}
- </el-button>
- </div>
- <div class="ele-text-center" style="margin-bottom: 10px">
- <!-- <i class="login-oauth-icon el-icon-_qq" style="background: #3492ed"></i>
- <i
- class="login-oauth-icon el-icon-_wechat"
- style="background: #4daf29"
- ></i>
- <i
- class="login-oauth-icon el-icon-_weibo"
- style="background: #cf1900"
- ></i> -->
- </div>
- </el-form>
- <div class="login-copyright">
- <!-- copyright © 2022 eleadmin.com all rights reserved. -->
- </div>
- <!-- 多语言切换 -->
- <div style="position: absolute; right: 30px; top: 20px">
- <i18n-icon
- :icon-style="{ fontSize: '22px', color: '#fff', cursor: 'pointer' }"
- />
- </div>
- <!-- 实际项目去掉这段 -->
- <!-- <div
- class="hidden-xs-only"
- style="position: absolute; right: 30px; bottom: 20px; z-index: 9"
- >
- <el-radio-group v-model="direction" size="mini">
- <el-radio-button label="2">居左</el-radio-button>
- <el-radio-button label="0">居中</el-radio-button>
- <el-radio-button label="1">居右</el-radio-button>
- </el-radio-group>
- </div> -->
- <el-dialog
- title="用户信息"
- :visible.sync="isInfo"
- v-if="isInfo"
- append-to-body
- width="30%"
- center
- :close-on-click-modal="false"
- @close="closeInfo"
- >
- <el-form :model="infoForm" label-position="right" label-width="100px">
- <el-form-item prop="factory" label="所属工厂">
- <el-input
- v-model="infoForm.factoryName"
- disabled
- placeholder="所属工厂"
- style="width: 240px"
- />
- </el-form-item>
- <el-form-item prop="team" label="班组">
- <el-select
- style="width: 240px"
- clearable
- v-model="infoForm.teamId"
- filterable
- placeholder="请选择班组"
- @change="changeTeam(infoForm.teamId)"
- >
- <el-option
- v-for="item in teamList"
- :label="item.teamName"
- :value="item.teamId"
- :key="item.teamId"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item prop="workCenter" label="工作中心">
- <el-select
- style="width: 240px"
- clearable
- v-model="infoForm.workCenterId"
- filterable
- placeholder="请选择工作中心"
- @change="changeWorlCenter(infoForm.workCenterId)"
- >
- <el-option
- v-for="item in workCenterList"
- :label="item.centerName"
- :value="item.centerId"
- :key="item.centerId"
- ></el-option>
- </el-select>
- <!-- <el-input
- v-model="infoForm.workCenter"
- disabled
- placeholder="所属工作中心"
- style="width: 240px"
- /> -->
- </el-form-item>
- <el-form-item prop="desk" label="工位">
- <!-- <el-input
- v-model="infoForm.desk"
- disabled
- placeholder="工位"
- style="width: 240px"
- /> -->
- <el-select
- style="width: 240px"
- clearable
- v-model="infoForm.workStationId"
- filterable
- placeholder="请选择工位"
- >
- <el-option
- v-for="item in workStationList"
- :label="item.workStationName"
- :value="item.workStationId"
- :key="item.workStationId"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item prop="device" label="设备">
- <!-- <el-input
- v-model="infoForm.device"
- disabled
- placeholder="设备"
- style="width: 240px"
- /> -->
- <el-select
- style="width: 240px"
- clearable
- v-model="infoForm.deviceId"
- filterable
- placeholder="请选择设备"
- >
- <el-option
- v-for="item in deviceList"
- :label="item.deviceName"
- :value="item.deviceId"
- :key="item.deviceId"
- ></el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="isInfo = false">取 消</el-button>
- <el-button type="primary" @click="infoClick">确 定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import I18nIcon from '@/layout/components/i18n-icon.vue';
- import { getToken } from '@/utils/token-util';
- import { login, getCaptcha, getUserInfo, getFactoryarea } from '@/api/login';
- import xyy from '@/assets/xyy.jpg';
- import { getPathAddress } from '@/api/system/file';
- import { setCurrentUser } from '@/utils/token-util';
- import { factoryareaId } from '@/api/system/user';
- export default {
- // eslint-disable-next-line vue/multi-word-component-names
- name: 'Login',
- components: { I18nIcon },
- data() {
- return {
- // 登录框方向, 0居中, 1居右, 2居左
- xyy,
- direction: 1,
- // 加载状态
- loading: false,
- // 表单数据
- form: {
- loginName: localStorage.getItem('accountInfo')
- ? JSON.parse(localStorage.getItem('accountInfo')).loginName
- : '',
- loginPwd: localStorage.getItem('accountInfo')
- ? JSON.parse(localStorage.getItem('accountInfo')).loginPwd
- : '',
- remember: localStorage.getItem('accountInfo')
- ? JSON.parse(localStorage.getItem('accountInfo')).remember
- : false,
- captcha: '',
- uuid: '',
- factory: '',
- device: '',
- team: '',
- workCenter: '',
- desk: ''
- },
- infoForm: {
- factoryId: '',
- workCenterId: '',
- teamId: '',
- workStationId: '',
- deviceId: '',
- factoryName: ''
- },
- // 验证码base64数据
- captcha: '',
- // 验证码内容, 实际项目去掉
- text: '',
- isInfo: false,
- factoryList: [],
- workCenterList: [],
- teamList: [],
- deviceList: [],
- workStationList: [],
- userData: null
- };
- },
- computed: {
- // 表单验证规则
- rules() {
- return {
- loginName: [
- {
- required: true,
- message: this.$t('请输入登录账号'),
- type: 'string',
- trigger: 'blur'
- }
- ],
- loginPwd: [
- {
- required: true,
- message: this.$t('请输入登录密码'),
- type: 'string',
- trigger: 'blur'
- }
- ],
- captcha: [
- {
- required: true,
- message: '验证码不能为空',
- type: 'string',
- trigger: 'blur'
- }
- ]
- };
- }
- },
- created() {
- this.changeCaptcha();
- if (getToken()) {
- this.goHome();
- } else {
- // 重置菜单权限
- this.$store.commit('user/setMenus', null);
- }
- },
- methods: {
- /* 提交 */
- submit() {
- this.$refs.form.validate((valid) => {
- if (!valid) {
- return false;
- }
- this.loading = true;
- login(this.form)
- .then(async (res) => {
- localStorage.setItem('userId', res.data.userId);
- // 用户信息
- if (res.data?.loginChangeGroupVOList.length > 0) {
- setCurrentUser(
- {
- currentGroupId: res.data.loginChangeGroupVOList[0].groupId,
- currentRoleId:
- res.data.loginChangeGroupVOList[0]
- .loginChangeRoleVOList[0].roleId
- },
- this.form.remember
- );
- }
- const filePath = await getPathAddress();
- res.data.avatarAddress =
- res.data.avatar && res.data.avatar.length
- ? filePath + res.data.avatar[0].storePath
- : xyy;
- if (res.data.factoryId) {
- let factoryareaData = await factoryareaId(res.data.factoryId);
- res.data['factoryName'] = factoryareaData.name;
- }
- this.$store.commit('user/setUserInfo', res.data);
- this.loading = false;
- this.$message.success(res.message);
- if (this.form.remember) {
- localStorage.setItem('accountInfo', JSON.stringify(this.form));
- } else {
- localStorage.removeItem('accountInfo');
- }
- await this.$store.dispatch('user/getCurrentUserAuthorityDept');
- await this.$store.dispatch('paramsSetData/setParamsDataInfo');
- this.goHome();
- })
- .catch((e) => {
- this.changeCaptcha();
- this.loading = false;
- // this.$message.error(e.message);
- });
- });
- },
- /* 跳转到首页 */
- goHome() {
- localStorage.setItem('singleUserInfo', '1');
- if (this.$store.state.user.info.teamId) {
- this.getFactoryareaList();
- this.getUserAllInfo();
- this.isInfo = true;
- } else {
- this.$message.warning('请先给该员工配置班组!!');
- }
- // this.getFactoryList()
- // this.$router.push(this.$route?.query?.from ?? '/').catch(() => {});
- },
- async getFactoryareaList() {
- await getFactoryarea({
- type: 1,
- size: 9999
- }).then((res) => {
- this.factoryList = res.list;
- });
- },
- async getUserAllInfo() {
- this.infoForm.factoryId = '';
- this.infoForm.workCenterId = '';
- this.infoForm.teamId = '';
- this.infoForm.workStationId = '';
- this.infoForm.deviceId = '';
- this.infoForm.factoryName = '';
- await getUserInfo(this.$store.state.user.info.userId).then((res) => {
- // this.infoForm.factoryName = res.factoryName;
- // if (res.factoryName) {
- // this.infoForm.factoryName = res.factoryName;
- // } else {
- const data = this.factoryList.find((it) => it.id == res.factoryId);
- // }
- this.infoForm.factoryId = res.factoryId;
- this.infoForm.factoryName = res.factoryName;
- this.teamList = res.teamList;
- this.userData = res;
- });
- },
- changeWorlCenter(centerId) {
- this.infoForm.workCenterId = centerId;
- this.infoForm.workStationId = '';
- const workCenterData = this.workCenterList.find(
- (item) => item.centerId == centerId
- );
- if (workCenterData) {
- if (this.userData.workStationList.length != 0) {
- this.workStationList = this.userData.workStationList.filter(
- (item) => item.centerId == centerId
- );
- }
- }
- },
- changeTeam(teamId) {
- this.infoForm.teamId = teamId;
- this.infoForm.deviceId = '';
- this.infoForm.workCenterId = '';
- console.log(this.userData, teamId, '111');
- // const teamData = this.teamList.find((item) => item.teamId == teamId);
- this.workCenterList = this.userData.centerList.filter(
- (it) => it.teamId == teamId
- );
- if (this.userData.deviceList.length != 0) {
- this.deviceList = this.userData.deviceList.filter(
- (it) => it.teamId == teamId
- );
- }
- },
- infoClick() {
- if (!this.infoForm.workCenterId) {
- return this.$message.warning('请选择工作中心');
- }
- if (!this.infoForm.teamId) {
- return this.$message.warning('请选择班组');
- }
- this.isInfo = false;
- // console.log(this.infoForm, 'this.infoForm');
- // this.$store.commit('user/setAllUserInfo', this.infoForm);
- localStorage.setItem('chooseUserInfo', JSON.stringify(this.infoForm));
- // console.log(this.$store.state.user, 'this.$store.state.user');
- this.$router.push(this.$route?.query?.from ?? '/').catch(() => {});
- },
- closeInfo() {
- this.isInfo = false;
- },
- /* 更换图形验证码 */
- changeCaptcha() {
- this.form.uuid = this.generateUUID();
- // 这里演示的验证码是后端返回base64格式的形式, 如果后端地址直接是图片请参考忘记密码页面
- getCaptcha({ uuid: this.form.uuid })
- .then((data) => {
- this.captcha = URL.createObjectURL(data.data);
- this.$refs?.form?.clearValidate();
- })
- .catch((e) => {
- // this.$message.error(e.message);
- });
- },
- generateUUID() {
- var d = new Date().getTime(); //Timestamp
- var d2 =
- (performance && performance.now && performance.now() * 1000) || 0; //Time in microseconds since page-load or 0 if unsupported
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
- /[xy]/g,
- function (c) {
- var r = Math.random() * 16; //random number between 0 and 16
- if (d > 0) {
- //Use timestamp until depleted
- r = (d + r) % 16 | 0;
- d = Math.floor(d / 16);
- } else {
- //Use microseconds since page-load if supported
- r = (d2 + r) % 16 | 0;
- d2 = Math.floor(d2 / 16);
- }
- return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
- }
- );
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- /* 背景 */
- .login-wrapper {
- padding: 50px 20px;
- position: relative;
- box-sizing: border-box;
- background-image: url('@/assets/bg-login.jpg');
- background-repeat: no-repeat;
- background-size: cover;
- min-height: 100vh;
- &:before {
- content: '';
- background-color: rgba(0, 0, 0, 0.2);
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- }
- }
- /* 卡片 */
- .login-form {
- margin: 0 auto;
- width: 360px;
- max-width: 100%;
- padding: 25px 30px;
- position: relative;
- box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
- box-sizing: border-box;
- border-radius: 4px;
- z-index: 2;
- h4 {
- text-align: center;
- margin: 0 0 25px 0;
- }
- & > .el-form-item {
- margin-bottom: 25px;
- }
- }
- .login-form-right .login-form {
- margin: 0 15% 0 auto;
- }
- .login-form-left .login-form {
- margin: 0 auto 0 15%;
- }
- /* 验证码 */
- .login-input-group {
- display: flex;
- align-items: center;
- :deep(.el-input) {
- flex: 1;
- }
- }
- .login-captcha {
- height: 38px;
- width: 102px;
- margin-left: 10px;
- border-radius: 4px;
- border: 1px solid #dcdfe6;
- text-align: center;
- cursor: pointer;
- &:hover {
- opacity: 0.75;
- }
- }
- .login-btn {
- display: block;
- width: 100%;
- }
- /* 第三方登录图标 */
- .login-oauth-icon {
- color: #fff;
- padding: 5px;
- margin: 0 10px;
- font-size: 18px;
- border-radius: 50%;
- cursor: pointer;
- }
- /* 底部版权 */
- .login-copyright {
- color: #eee;
- padding-top: 20px;
- text-align: center;
- position: relative;
- z-index: 1;
- }
- /* 响应式 */
- @media screen and (min-height: 550px) {
- .login-form {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translateX(-50%);
- margin-top: -220px;
- }
- .login-form-right .login-form,
- .login-form-left .login-form {
- left: auto;
- right: 15%;
- transform: translateX(0);
- margin: -220px auto auto auto;
- }
- .login-form-left .login-form {
- right: auto;
- left: 15%;
- }
- .login-copyright {
- position: absolute;
- bottom: 20px;
- right: 0;
- left: 0;
- }
- }
- @media screen and (max-width: 768px) {
- .login-form-right .login-form,
- .login-form-left .login-form {
- left: 50%;
- right: auto;
- transform: translateX(-50%);
- margin-right: auto;
- }
- }
- </style>
|