UNPKG

w-vue-middle

Version:

统一公共服务组件

159 lines (154 loc) 4.35 kB
/* * @Author: Jason Liu * @Date: 2023-05-06 15:21:46 * @Desc: */ const $appService = require('../../api/appService'); import { nextApp } from '../../utils/auth'; //鉴权 import _ from 'lodash'; export default { data() { return { loading: false, isCache: true, //是否缓存用户 labelCol: { span: 0 }, wrapperCol: { span: 24 }, isCode: 0, codeImg: '', uuid: undefined, hospitalloading: false, hospitallist: [], form: { code: '', username: undefined, password: undefined, orgId: undefined, //院区 }, rules: { username: [{ required: true, message: $t('请输入用户名称!'), trigger: 'blur' }], password: [{ required: true, message: $t('请输入登录密码!'), trigger: 'blur' }], // code: [ // { required: true, message: "请输入验证码!", trigger: "blur" }, // ], }, captchaTimer: undefined, //验证码定时器 }; }, created() { this.isCache = Boolean($storage.get('USERCTR')); if (this.isCache) { let from = $storage.get('USERFROM', true); this.form = Object.assign( { code: '', username: undefined, password: undefined, orgId: undefined, }, from, ); this.getHospitalInfo(); } this.sysConfigByKey(); }, methods: { /** * @Author: Jason Liu * @description: 获取院区信息 */ getHospitalInfo: _.debounce(function () { if (!this.hospitalloading && this.form.username) { //锁 this.hospitalloading = true; $appService .getHospitalInfo({ userId: this.form.username, }) .then((req) => { this.hospitallist = req.data.map((item, i) => { if (i == 0) { this.form.orgId = item.dataCode; } return { value: item.dataId || item.dataCode, label: item.dataName, }; }); }) .finally(() => { this.hospitalloading = false; }); } }, 200), /** * @Author: y_zp * @description: 是否配置验证码 */ sysConfigByKey() { $appService.sysConfigByKey('system.captchaEnabled').then((req) => { this.isCode = req.data; // 0 关闭验证码;1 开启验证码 if (this.isCode == '1') { this.getCaptchaImage(); this.rules.code = [{ required: true, message: $t('请输入验证码!'), trigger: 'blur' }]; } }); }, /** * @Author: y_zp * @description: 获取验证码 */ getCaptchaImage() { clearTimeout(this.captchaTimer); $appService.captchaImage().then((req) => { this.codeImg = 'data:image/gif;base64,' + req.data.img; this.uuid = req.data.uuid; this.captchaTimer = setTimeout(() => { this.getCaptchaImage(); }, 280000); }); }, /** * @Author: Jason Liu * @description: 设置缓存 */ setCache() { $storage.set('USERCTR', this.isCache); if (!this.isCache) { $storage.set('USERFROM', undefined); } }, /** * @Author: Jason Liu * @description: 提交登录 */ onSubmit() { this.$refs.userFrom.validate((valid) => { if (valid) { this.loading = true; let param = { orgId: this.form.orgId, password: this.$encrypt(this.form.password), //password: this.form.password, userId: this.form.username, code: this.form.code, uuid: this.uuid, }; $appService .login(param) .then((req) => { if (this.isCache) { $storage.set('USERFROM', this.form); } nextApp(this); }) .finally(() => { this.loading = false; if (this.isCode == '1') { this.getCaptchaImage(); } }); } }); }, }, };