Pre Merge pull request !75 from H0nGzA1/hongzai_dev
commit
af59b1c16b
3
web/.env
3
web/.env
|
@ -3,7 +3,8 @@
|
|||
# 页面 title 前缀
|
||||
VUE_APP_TITLE=D2Admin
|
||||
|
||||
# 网络请求公用地址
|
||||
# 网络请求公用地址,如果打包之后多一层去掉/api
|
||||
|
||||
VUE_APP_API=/api/
|
||||
|
||||
# 仓库地址
|
||||
|
|
|
@ -7,3 +7,4 @@ VUE_APP_PM_ENABLED = true
|
|||
# 后端接口地址及端口(域名)
|
||||
VUE_APP_API = "http://127.0.0.1:8000"
|
||||
|
||||
VUE_APP_WEB_SOCKET_URL = 'ws://127.0.0.1:8000'
|
|
@ -13,3 +13,5 @@ VUE_APP_SCOURCE_LINK=FALSE
|
|||
VUE_APP_PUBLIC_PATH=/
|
||||
# 启用权限管理
|
||||
VUE_APP_PM_ENABLED = true
|
||||
|
||||
VUE_APP_WEB_SOCKET_URL = 'ws://127.0.0.1:8000'
|
|
@ -13,3 +13,5 @@ VUE_APP_SCOURCE_LINK=FALSE
|
|||
VUE_APP_PUBLIC_PATH=/
|
||||
# 启用权限管理
|
||||
VUE_APP_PM_ENABLED = true
|
||||
|
||||
VUE_APP_WEB_SOCKET_URL = 'ws://127.0.0.1:8000'
|
|
@ -7,3 +7,4 @@ VUE_APP_PM_ENABLED = true
|
|||
# 后端接口地址及端口(域名)
|
||||
VUE_APP_API = "http://127.0.0.1:8000/"
|
||||
|
||||
VUE_APP_WEB_SOCKET_URL = 'ws://127.0.0.1:8000'
|
|
@ -1,70 +1,73 @@
|
|||
import ElementUI from 'element-ui'
|
||||
import util from '@/libs/util'
|
||||
function initWebSocket (e) {
|
||||
const token = util.cookies.get('token')
|
||||
import ElementUI from "element-ui";
|
||||
import util from "@/libs/util";
|
||||
function initWebSocket(e) {
|
||||
const token = util.cookies.get("token");
|
||||
if (token) {
|
||||
const wsUri = 'ws://127.0.0.1:8000/?auth=' + token
|
||||
this.socket = new WebSocket(wsUri)// 这里面的this都指向vue
|
||||
this.socket.onerror = webSocketOnError
|
||||
this.socket.onmessage = webSocketOnMessage
|
||||
this.socket.onclose = closeWebsocket
|
||||
// console.log(object);
|
||||
const wsUri = util.webSocketURL() + "/?auth=" + token;
|
||||
this.socket = new WebSocket(wsUri); // 这里面的this都指向vue
|
||||
this.socket.onerror = webSocketOnError;
|
||||
this.socket.onmessage = webSocketOnMessage;
|
||||
this.socket.onclose = closeWebsocket;
|
||||
}
|
||||
}
|
||||
|
||||
function webSocketOnError (e) {
|
||||
function webSocketOnError(e) {
|
||||
ElementUI.Notification({
|
||||
title: '',
|
||||
message: 'WebSocket连接发生错误' + JSON.stringify(e),
|
||||
type: 'error',
|
||||
position: 'bottom-right',
|
||||
duration: 3000
|
||||
})
|
||||
title: "",
|
||||
message: "WebSocket连接发生错误" + JSON.stringify(e),
|
||||
type: "error",
|
||||
position: "bottom-right",
|
||||
duration: 3000,
|
||||
});
|
||||
}
|
||||
function webSocketOnMessage (e) {
|
||||
const data = JSON.parse(e.data)
|
||||
if (data.contentType === 'INFO') {
|
||||
function webSocketOnMessage(e) {
|
||||
const data = JSON.parse(e.data);
|
||||
if (data.contentType === "INFO") {
|
||||
ElementUI.Notification({
|
||||
title: 'websocket',
|
||||
title: "websocket",
|
||||
message: data.content,
|
||||
type: 'success',
|
||||
position: 'bottom-right',
|
||||
duration: 3000
|
||||
})
|
||||
} else if (data.contentType === 'ERROR') {
|
||||
type: "success",
|
||||
position: "bottom-right",
|
||||
duration: 3000,
|
||||
});
|
||||
} else if (data.contentType === "ERROR") {
|
||||
ElementUI.Notification({
|
||||
title: '',
|
||||
title: "",
|
||||
message: data.content,
|
||||
type: 'error',
|
||||
position: 'bottom-right',
|
||||
duration: 0
|
||||
})
|
||||
} else if (data.contentType === 'TEXT') {
|
||||
type: "error",
|
||||
position: "bottom-right",
|
||||
duration: 0,
|
||||
});
|
||||
} else if (data.contentType === "TEXT") {
|
||||
ElementUI.Notification({
|
||||
title: '温馨提示',
|
||||
title: "温馨提示",
|
||||
message: data.content,
|
||||
type: 'success',
|
||||
position: 'bottom-right',
|
||||
duration: 0
|
||||
})
|
||||
type: "success",
|
||||
position: "bottom-right",
|
||||
duration: 0,
|
||||
});
|
||||
} else {
|
||||
console.log(data.content)
|
||||
console.log(data.content);
|
||||
}
|
||||
}
|
||||
// 关闭websiocket
|
||||
function closeWebsocket () {
|
||||
console.log('连接已关闭...')
|
||||
close()
|
||||
function closeWebsocket() {
|
||||
console.log("连接已关闭...");
|
||||
close();
|
||||
}
|
||||
function close () {
|
||||
this.socket.close() // 关闭 websocket
|
||||
function close() {
|
||||
this.socket.close(); // 关闭 websocket
|
||||
this.socket.onclose = function (e) {
|
||||
console.log(e)// 监听关闭事件
|
||||
console.log('关闭')
|
||||
}
|
||||
console.log(e); // 监听关闭事件
|
||||
console.log("关闭");
|
||||
};
|
||||
}
|
||||
function webSocketSend (message) {
|
||||
this.socket.send(JSON.stringify(message))
|
||||
function webSocketSend(message) {
|
||||
this.socket.send(JSON.stringify(message));
|
||||
}
|
||||
export default {
|
||||
initWebSocket, close, webSocketSend
|
||||
}
|
||||
initWebSocket,
|
||||
close,
|
||||
webSocketSend,
|
||||
};
|
||||
|
|
|
@ -123,175 +123,177 @@
|
|||
</d2-container>
|
||||
</template>
|
||||
<script>
|
||||
import util from '@/libs/util.js'
|
||||
import { request } from '@/api/service'
|
||||
import { mapActions } from 'vuex'
|
||||
import util from "@/libs/util.js";
|
||||
import { request } from "@/api/service";
|
||||
import { mapActions } from "vuex";
|
||||
export default {
|
||||
name: 'userInfo',
|
||||
data () {
|
||||
name: "userInfo",
|
||||
data() {
|
||||
var validatePass = (rule, value, callback) => {
|
||||
const pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{8,30}')
|
||||
if (value === '') {
|
||||
callback(new Error('请输入密码'))
|
||||
const pwdRegex = new RegExp("(?=.*[0-9])(?=.*[a-zA-Z]).{8,30}");
|
||||
if (value === "") {
|
||||
callback(new Error("请输入密码"));
|
||||
} else if (value === this.userPasswordInfo.oldPassword) {
|
||||
callback(new Error('原密码与新密码一致'))
|
||||
callback(new Error("原密码与新密码一致"));
|
||||
} else if (!pwdRegex.test(value)) {
|
||||
callback(new Error('您的密码复杂度太低(密码中必须包含字母、数字)'))
|
||||
callback(new Error("您的密码复杂度太低(密码中必须包含字母、数字)"));
|
||||
} else {
|
||||
if (this.userPasswordInfo.newPassword2 !== '') {
|
||||
this.$refs.userPasswordForm.validateField('newPassword2')
|
||||
if (this.userPasswordInfo.newPassword2 !== "") {
|
||||
this.$refs.userPasswordForm.validateField("newPassword2");
|
||||
}
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
var validatePass2 = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请再次输入密码'))
|
||||
if (value === "") {
|
||||
callback(new Error("请再次输入密码"));
|
||||
} else if (value !== this.userPasswordInfo.newPassword) {
|
||||
callback(new Error('两次输入密码不一致!'))
|
||||
callback(new Error("两次输入密码不一致!"));
|
||||
} else {
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
return {
|
||||
position: 'left',
|
||||
activeName: 'userInfo',
|
||||
action: util.baseURL() + 'api/system/file/',
|
||||
position: "left",
|
||||
activeName: "userInfo",
|
||||
action: util.baseURL() + "api/system/file/",
|
||||
headers: {
|
||||
Authorization: 'JWT ' + util.cookies.get('token')
|
||||
Authorization: "JWT " + util.cookies.get("token"),
|
||||
},
|
||||
fileList: [],
|
||||
userInfo: {
|
||||
name: '',
|
||||
gender: '',
|
||||
mobile: '',
|
||||
avatar: '',
|
||||
email: ''
|
||||
name: "",
|
||||
gender: "",
|
||||
mobile: "",
|
||||
avatar: "",
|
||||
email: "",
|
||||
},
|
||||
userInforules: {
|
||||
name: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
mobile: [{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确手机号' }]
|
||||
name: [{ required: true, message: "请输入昵称", trigger: "blur" }],
|
||||
mobile: [{ pattern: /^1[3-9]\d{9}$/, message: "请输入正确手机号" }],
|
||||
},
|
||||
userPasswordInfo: {
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
newPassword2: ''
|
||||
oldPassword: "",
|
||||
newPassword: "",
|
||||
newPassword2: "",
|
||||
},
|
||||
passwordRules: {
|
||||
oldPassword: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入原密码',
|
||||
trigger: 'blur'
|
||||
}
|
||||
message: "请输入原密码",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
newPassword: [{ validator: validatePass, trigger: 'blur' }],
|
||||
newPassword2: [{ validator: validatePass2, trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
newPassword: [{ validator: validatePass, trigger: "blur" }],
|
||||
newPassword2: [{ validator: validatePass2, trigger: "blur" }],
|
||||
},
|
||||
};
|
||||
},
|
||||
mounted () {
|
||||
this.getCurrentUserInfo()
|
||||
mounted() {
|
||||
this.getCurrentUserInfo();
|
||||
},
|
||||
methods: {
|
||||
...mapActions('d2admin/account', ['logout']),
|
||||
...mapActions("d2admin/account", ["logout"]),
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*/
|
||||
getCurrentUserInfo () {
|
||||
const _self = this
|
||||
getCurrentUserInfo() {
|
||||
const _self = this;
|
||||
return request({
|
||||
url: '/api/system/user/user_info/',
|
||||
method: 'get',
|
||||
params: {}
|
||||
url: "/api/system/user/user_info/",
|
||||
method: "get",
|
||||
params: {},
|
||||
}).then((res) => {
|
||||
_self.userInfo = res.data
|
||||
_self.fileList = [{ name: 'avatar.png', url: res.data.avatar }]
|
||||
})
|
||||
_self.userInfo = res.data;
|
||||
_self.fileList = res.data.avatar
|
||||
? [{ name: "avatar.png", url: res.data.avatar }]
|
||||
: [];
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
updateInfo () {
|
||||
const _self = this
|
||||
updateInfo() {
|
||||
const _self = this;
|
||||
|
||||
_self.$refs.userInfoForm.validate((valid) => {
|
||||
if (valid) {
|
||||
request({
|
||||
url: '/api/system/user/update_user_info/',
|
||||
method: 'put',
|
||||
data: _self.userInfo
|
||||
url: "/api/system/user/update_user_info/",
|
||||
method: "put",
|
||||
data: _self.userInfo,
|
||||
}).then((res) => {
|
||||
_self.$message.success('修改成功')
|
||||
_self.getCurrentUserInfo()
|
||||
})
|
||||
_self.$message.success("修改成功");
|
||||
_self.getCurrentUserInfo();
|
||||
});
|
||||
} else {
|
||||
// 校验失败
|
||||
// 登录表单校验失败
|
||||
this.$message.error('表单校验失败,请检查')
|
||||
this.$message.error("表单校验失败,请检查");
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
// 重置
|
||||
resetForm (name) {
|
||||
const _self = this
|
||||
if (name === 'info') {
|
||||
_self.getCurrentUserInfo()
|
||||
resetForm(name) {
|
||||
const _self = this;
|
||||
if (name === "info") {
|
||||
_self.getCurrentUserInfo();
|
||||
} else {
|
||||
_self.userPasswordForm = {}
|
||||
_self.userPasswordForm = {};
|
||||
}
|
||||
},
|
||||
// tab切换
|
||||
handleClick (tab, event) {
|
||||
const _self = this
|
||||
if (tab.paneName === 'userInfo') {
|
||||
_self.$refs.userPasswordForm.resetFields()
|
||||
_self.getCurrentUserInfo()
|
||||
handleClick(tab, event) {
|
||||
const _self = this;
|
||||
if (tab.paneName === "userInfo") {
|
||||
_self.$refs.userPasswordForm.resetFields();
|
||||
_self.getCurrentUserInfo();
|
||||
} else {
|
||||
_self.$refs.userInfoForm.resetFields()
|
||||
_self.$refs.userInfoForm.resetFields();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 重新设置密码
|
||||
*/
|
||||
settingPassword () {
|
||||
const _self = this
|
||||
settingPassword() {
|
||||
const _self = this;
|
||||
|
||||
_self.$refs.userPasswordForm.validate((valid) => {
|
||||
if (valid) {
|
||||
const userId = util.cookies.get('uuid')
|
||||
const userId = util.cookies.get("uuid");
|
||||
if (userId) {
|
||||
const params = JSON.parse(JSON.stringify(_self.userPasswordInfo))
|
||||
params.oldPassword = _self.$md5(params.oldPassword)
|
||||
params.newPassword = _self.$md5(params.newPassword)
|
||||
params.newPassword2 = _self.$md5(params.newPassword2)
|
||||
const params = JSON.parse(JSON.stringify(_self.userPasswordInfo));
|
||||
params.oldPassword = _self.$md5(params.oldPassword);
|
||||
params.newPassword = _self.$md5(params.newPassword);
|
||||
params.newPassword2 = _self.$md5(params.newPassword2);
|
||||
request({
|
||||
url: '/api/system/user/' + userId + '/change_password/',
|
||||
method: 'put',
|
||||
data: params
|
||||
url: "/api/system/user/" + userId + "/change_password/",
|
||||
method: "put",
|
||||
data: params,
|
||||
}).then((res) => {
|
||||
_self.activeName = 'userInfo'
|
||||
_self.$message.success('修改成功')
|
||||
_self.logout({})
|
||||
})
|
||||
_self.activeName = "userInfo";
|
||||
_self.$message.success("修改成功");
|
||||
_self.logout({});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 校验失败
|
||||
// 登录表单校验失败
|
||||
this.$message.error('表单校验失败,请检查')
|
||||
this.$message.error("表单校验失败,请检查");
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 头像上传
|
||||
* @param res
|
||||
* @param file
|
||||
*/
|
||||
handleAvatarSuccess (res, file) {
|
||||
console.log(11, res)
|
||||
this.fileList = [{ url: util.baseURL() + res.data.url, name: file.name }]
|
||||
this.userInfo.avatar = util.baseURL() + res.data.url
|
||||
}
|
||||
}
|
||||
}
|
||||
handleAvatarSuccess(res, file) {
|
||||
console.log(11, res);
|
||||
this.fileList = [{ url: util.baseURL() + res.data.url, name: file.name }];
|
||||
this.userInfo.avatar = util.baseURL() + res.data.url;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -1,82 +1,102 @@
|
|||
import cookies from './util.cookies'
|
||||
import db from './util.db'
|
||||
import log from './util.log'
|
||||
import dayjs from 'dayjs'
|
||||
import filterParams from './util.params'
|
||||
import cookies from "./util.cookies";
|
||||
import db from "./util.db";
|
||||
import log from "./util.log";
|
||||
import dayjs from "dayjs";
|
||||
import filterParams from "./util.params";
|
||||
|
||||
const util = {
|
||||
cookies,
|
||||
db,
|
||||
log,
|
||||
filterParams
|
||||
}
|
||||
filterParams,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 更新标题
|
||||
* @param {String} titleText 标题
|
||||
*/
|
||||
util.title = function (titleText) {
|
||||
const processTitle = process.env.VUE_APP_TITLE || 'D2Admin'
|
||||
window.document.title = `${processTitle}${titleText ? ` | ${titleText}` : ''}`
|
||||
}
|
||||
const processTitle = process.env.VUE_APP_TITLE || "D2Admin";
|
||||
window.document.title = `${processTitle}${
|
||||
titleText ? ` | ${titleText}` : ""
|
||||
}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 打开新页面
|
||||
* @param {String} url 地址
|
||||
*/
|
||||
util.open = function (url) {
|
||||
var a = document.createElement('a')
|
||||
a.setAttribute('href', url)
|
||||
a.setAttribute('target', '_blank')
|
||||
a.setAttribute('id', 'd2admin-link-temp')
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(document.getElementById('d2admin-link-temp'))
|
||||
}
|
||||
var a = document.createElement("a");
|
||||
a.setAttribute("href", url);
|
||||
a.setAttribute("target", "_blank");
|
||||
a.setAttribute("id", "d2admin-link-temp");
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(document.getElementById("d2admin-link-temp"));
|
||||
};
|
||||
/**
|
||||
* @description 校验是否为租户模式。租户模式把域名替换成 域名 加端口
|
||||
*/
|
||||
util.baseURL = function () {
|
||||
var baseURL = process.env.VUE_APP_API
|
||||
if (window.pluginsAll && window.pluginsAll.indexOf('dvadmin-tenant-web') !== -1) {
|
||||
var baseURL = process.env.VUE_APP_API;
|
||||
if (
|
||||
window.pluginsAll &&
|
||||
window.pluginsAll.indexOf("dvadmin-tenant-web") !== -1
|
||||
) {
|
||||
// document.domain
|
||||
var host = baseURL.split('/')[2]
|
||||
var prot = host.split(':')[1] || 80
|
||||
host = document.domain + ':' + prot
|
||||
baseURL = baseURL.split('/')[0] + '//' + baseURL.split('/')[1] + host + '/' + (baseURL.split('/')[3] || '')
|
||||
var host = baseURL.split("/")[2];
|
||||
var prot = host.split(":")[1] || 80;
|
||||
host = document.domain + ":" + prot;
|
||||
baseURL =
|
||||
baseURL.split("/")[0] +
|
||||
"//" +
|
||||
baseURL.split("/")[1] +
|
||||
host +
|
||||
"/" +
|
||||
(baseURL.split("/")[3] || "");
|
||||
}
|
||||
if (!baseURL.endsWith('/')) {
|
||||
baseURL += '/'
|
||||
if (!baseURL.endsWith("/")) {
|
||||
baseURL += "/";
|
||||
}
|
||||
return baseURL
|
||||
}
|
||||
return baseURL;
|
||||
};
|
||||
/*
|
||||
* 获取websocket地址
|
||||
*/
|
||||
util.webSocketURL = function () {
|
||||
return process.env.VUE_APP_WEB_SOCKET_URL;
|
||||
};
|
||||
|
||||
/**
|
||||
* 自动生成ID
|
||||
*/
|
||||
util.autoCreateCode = function () {
|
||||
return dayjs().format('YYYYMMDDHHmmssms') + Math.round(Math.random() * 80 + 20)
|
||||
}
|
||||
return (
|
||||
dayjs().format("YYYYMMDDHHmmssms") + Math.round(Math.random() * 80 + 20)
|
||||
);
|
||||
};
|
||||
/**
|
||||
* 自动生成短 ID
|
||||
*/
|
||||
util.autoShortCreateCode = function () {
|
||||
var Num = ''
|
||||
var Num = "";
|
||||
for (var i = 0; i < 4; i++) {
|
||||
Num += Math.floor(Math.random() * 10)
|
||||
Num += Math.floor(Math.random() * 10);
|
||||
}
|
||||
return dayjs().format('YYMMDD') + Num
|
||||
}
|
||||
return dayjs().format("YYMMDD") + Num;
|
||||
};
|
||||
|
||||
/**
|
||||
* 生产随机字符串
|
||||
*/
|
||||
util.randomString = function (e) {
|
||||
e = e || 32
|
||||
var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
|
||||
var a = t.length
|
||||
var n = ''
|
||||
for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a))
|
||||
return n
|
||||
}
|
||||
e = e || 32;
|
||||
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
|
||||
var a = t.length;
|
||||
var n = "";
|
||||
for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
|
||||
return n;
|
||||
};
|
||||
|
||||
export default util
|
||||
export default util;
|
||||
|
|
|
@ -7,52 +7,51 @@
|
|||
* @文件介绍:
|
||||
*/
|
||||
// Vue
|
||||
import Vue from 'vue'
|
||||
import i18n from './i18n'
|
||||
import App from './App'
|
||||
import Vue from "vue";
|
||||
import i18n from "./i18n";
|
||||
import App from "./App";
|
||||
// 核心插件
|
||||
import d2Admin from '@/plugin/d2admin'
|
||||
import d2Admin from "@/plugin/d2admin";
|
||||
// store
|
||||
import store from '@/store/index'
|
||||
import store from "@/store/index";
|
||||
|
||||
// 菜单和路由设置
|
||||
import router from './router'
|
||||
import { menuHeader } from '@/menu'
|
||||
import router from "./router";
|
||||
import { menuHeader } from "@/menu";
|
||||
|
||||
// 按钮权限
|
||||
import '@/plugin/permission' // 加载permission
|
||||
import "@/plugin/permission"; // 加载permission
|
||||
|
||||
// d2-crud-plus 安装与初始化
|
||||
import './install'
|
||||
import "./install";
|
||||
// 配置vxe-table
|
||||
import 'xe-utils'
|
||||
import VXETable from 'vxe-table'
|
||||
import 'vxe-table/lib/style.css'
|
||||
import "xe-utils";
|
||||
import VXETable from "vxe-table";
|
||||
import "vxe-table/lib/style.css";
|
||||
|
||||
// md5加密
|
||||
import md5 from 'js-md5'
|
||||
import md5 from "js-md5";
|
||||
|
||||
// websocket
|
||||
import websocket from '@/api/websocket'
|
||||
import websocket from "@/api/websocket";
|
||||
|
||||
// 核心插件
|
||||
Vue.use(d2Admin)
|
||||
Vue.use(VXETable)
|
||||
Vue.prototype.$md5 = md5
|
||||
Vue.prototype.$websocket = websocket
|
||||
Vue.use(d2Admin);
|
||||
Vue.use(VXETable);
|
||||
Vue.prototype.$md5 = md5;
|
||||
Vue.prototype.$websocket = websocket;
|
||||
|
||||
new Vue({
|
||||
router,
|
||||
store,
|
||||
i18n,
|
||||
render: h => h(App),
|
||||
beforeCreate () {
|
||||
render: (h) => h(App),
|
||||
beforeCreate() {
|
||||
// 初始化配置
|
||||
this.$store.dispatch('d2admin/settings/load')
|
||||
this.$store.dispatch('d2admin/dictionary/load')
|
||||
this.$store.dispatch("d2admin/settings/load");
|
||||
this.$store.dispatch("d2admin/dictionary/load");
|
||||
},
|
||||
created () {
|
||||
|
||||
created() {
|
||||
// 处理路由 得到每一级的路由设置
|
||||
// this.$store.commit('d2admin/page/init', frameInRoutes)
|
||||
// 设置顶栏菜单
|
||||
|
@ -62,28 +61,30 @@ new Vue({
|
|||
// 初始化菜单搜索功能
|
||||
// this.$store.commit('d2admin/search/init', menuAside)
|
||||
},
|
||||
mounted () {
|
||||
mounted() {
|
||||
// 展示系统信息
|
||||
this.$store.commit('d2admin/releases/versionShow')
|
||||
this.$store.commit("d2admin/releases/versionShow");
|
||||
// 用户登录后从数据库加载一系列的设置
|
||||
this.$store.dispatch('d2admin/account/load')
|
||||
this.$store.dispatch("d2admin/account/load");
|
||||
// 获取并记录用户 UA
|
||||
this.$store.commit('d2admin/ua/get')
|
||||
this.$store.commit("d2admin/ua/get");
|
||||
// 初始化全屏监听
|
||||
this.$store.dispatch('d2admin/fullscreen/listen')
|
||||
this.$store.dispatch("d2admin/fullscreen/listen");
|
||||
},
|
||||
watch: {
|
||||
// 检测路由变化切换侧边栏内容
|
||||
'$route.matched': {
|
||||
handler (matched) {
|
||||
"$route.matched": {
|
||||
handler(matched) {
|
||||
if (matched.length > 0) {
|
||||
const _side = menuHeader.filter(menu => menu.path === matched[0].path)
|
||||
const _side = menuHeader.filter(
|
||||
(menu) => menu.path === matched[0].path
|
||||
);
|
||||
if (_side.length > 0) {
|
||||
this.$store.commit('d2admin/menu/asideSet', _side[0].children)
|
||||
this.$store.commit("d2admin/menu/asideSet", _side[0].children);
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
}
|
||||
}).$mount('#app')
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
}).$mount("#app");
|
||||
|
|
|
@ -3,76 +3,78 @@ export default {
|
|||
// 支持快捷键 例如 ctrl+shift+s
|
||||
hotkey: {
|
||||
search: {
|
||||
open: 's',
|
||||
close: 'esc'
|
||||
}
|
||||
open: "s",
|
||||
close: "esc",
|
||||
},
|
||||
},
|
||||
// 侧边栏默认配置
|
||||
menu: {
|
||||
asideCollapse: false,
|
||||
asideTransition: true
|
||||
asideTransition: true,
|
||||
},
|
||||
// 在读取持久化数据失败时默认页面
|
||||
page: {
|
||||
opened: [
|
||||
{
|
||||
name: 'index',
|
||||
fullPath: '/index',
|
||||
name: "index",
|
||||
fullPath: "/index",
|
||||
meta: {
|
||||
title: '控制台',
|
||||
auth: false
|
||||
}
|
||||
}
|
||||
]
|
||||
title: "控制台",
|
||||
auth: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// 菜单搜索
|
||||
search: {
|
||||
enable: true
|
||||
enable: true,
|
||||
},
|
||||
// 注册的主题
|
||||
theme: {
|
||||
list: [
|
||||
{
|
||||
title: 'd2admin 经典',
|
||||
name: 'd2',
|
||||
preview: 'image/theme/d2/preview@2x.png'
|
||||
title: "d2admin 经典",
|
||||
name: "d2",
|
||||
preview: "image/theme/d2/preview@2x.png",
|
||||
},
|
||||
{
|
||||
title: 'Chester',
|
||||
name: 'chester',
|
||||
preview: 'image/theme/chester/preview@2x.jpg'
|
||||
title: "Chester",
|
||||
name: "chester",
|
||||
preview: "image/theme/chester/preview@2x.jpg",
|
||||
},
|
||||
{
|
||||
title: 'Element',
|
||||
name: 'element',
|
||||
preview: 'image/theme/element/preview@2x.jpg'
|
||||
title: "Element",
|
||||
name: "element",
|
||||
preview: "image/theme/element/preview@2x.jpg",
|
||||
},
|
||||
{
|
||||
title: '紫罗兰',
|
||||
name: 'violet',
|
||||
preview: 'image/theme/violet/preview@2x.jpg'
|
||||
title: "紫罗兰",
|
||||
name: "violet",
|
||||
preview: "image/theme/violet/preview@2x.jpg",
|
||||
},
|
||||
{
|
||||
title: '简约线条',
|
||||
name: 'line',
|
||||
backgroundImage: 'image/theme/line/bg.jpg',
|
||||
preview: 'image/theme/line/preview@2x.jpg'
|
||||
title: "简约线条",
|
||||
name: "line",
|
||||
backgroundImage: "image/theme/line/bg.jpg",
|
||||
preview: "image/theme/line/preview@2x.jpg",
|
||||
},
|
||||
{
|
||||
title: '流星',
|
||||
name: 'star',
|
||||
backgroundImage: 'image/theme/star/bg.jpg',
|
||||
preview: 'image/theme/star/preview@2x.jpg'
|
||||
title: "流星",
|
||||
name: "star",
|
||||
backgroundImage: "image/theme/star/bg.jpg",
|
||||
preview: "image/theme/star/preview@2x.jpg",
|
||||
},
|
||||
{
|
||||
title: 'Tomorrow Night Blue (vsCode)',
|
||||
name: 'tomorrow-night-blue',
|
||||
preview: 'image/theme/tomorrow-night-blue/preview@2x.jpg'
|
||||
}
|
||||
]
|
||||
title: "Tomorrow Night Blue (vsCode)",
|
||||
name: "tomorrow-night-blue",
|
||||
preview: "image/theme/tomorrow-night-blue/preview@2x.jpg",
|
||||
},
|
||||
],
|
||||
},
|
||||
// 是否默认开启页面切换动画
|
||||
transition: {
|
||||
active: true
|
||||
}
|
||||
}
|
||||
active: true,
|
||||
},
|
||||
// 设置默认主题
|
||||
defaultTheme: "d2",
|
||||
};
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
* 联系Qq:1638245306
|
||||
* @文件介绍: 登录和登出
|
||||
*/
|
||||
import { Message, MessageBox } from 'element-ui'
|
||||
import util from '@/libs/util.js'
|
||||
import router from '@/router'
|
||||
import store from '@/store/index'
|
||||
import { SYS_USER_LOGIN, SYS_USER_LOGOUT } from '@/views/system/login/api'
|
||||
import { Message, MessageBox } from "element-ui";
|
||||
import util from "@/libs/util.js";
|
||||
import router from "@/router";
|
||||
import store from "@/store/index";
|
||||
import { SYS_USER_LOGIN, SYS_USER_LOGOUT } from "@/views/system/login/api";
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
|
@ -22,95 +22,101 @@ export default {
|
|||
* @param {Object} payload password {String} 密码
|
||||
* @param {Object} payload route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
|
||||
*/
|
||||
async login ({ dispatch }, {
|
||||
username = '',
|
||||
password = '',
|
||||
captcha = '',
|
||||
captchaKey = ''
|
||||
} = {}) {
|
||||
async login(
|
||||
{ dispatch },
|
||||
{ username = "", password = "", captcha = "", captchaKey = "" } = {}
|
||||
) {
|
||||
let res = await SYS_USER_LOGIN({
|
||||
username,
|
||||
password,
|
||||
captcha,
|
||||
captchaKey
|
||||
})
|
||||
captchaKey,
|
||||
});
|
||||
// 设置 cookie 一定要存 uuid 和 token 两个 cookie
|
||||
// 整个系统依赖这两个数据进行校验和存储
|
||||
// uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复
|
||||
// token 代表用户当前登录状态 建议在网络请求中携带 token
|
||||
// 如有必要 token 需要定时更新,默认保存一天
|
||||
res = res.data
|
||||
util.cookies.set('uuid', res.userId)
|
||||
util.cookies.set('token', res.access)
|
||||
util.cookies.set('refresh', res.refresh)
|
||||
res = res.data;
|
||||
util.cookies.set("uuid", res.userId);
|
||||
util.cookies.set("token", res.access);
|
||||
util.cookies.set("refresh", res.refresh);
|
||||
// 设置 vuex 用户信息
|
||||
await dispatch('d2admin/user/set', { name: res.name, user_id: res.userId, avatar: res.avatar }, { root: true })
|
||||
await dispatch(
|
||||
"d2admin/user/set",
|
||||
{ name: res.name, user_id: res.userId, avatar: res.avatar },
|
||||
{ root: true }
|
||||
);
|
||||
// 用户登录后从持久化数据加载一系列的设置
|
||||
await dispatch('load')
|
||||
await dispatch("load");
|
||||
},
|
||||
/**
|
||||
* @description 注销用户并返回登录页面
|
||||
* @param {Object} context
|
||||
* @param {Object} payload confirm {Boolean} 是否需要确认
|
||||
*/
|
||||
logout ({ commit, dispatch }, { confirm = false } = {}) {
|
||||
logout({ commit, dispatch }, { confirm = false } = {}) {
|
||||
/**
|
||||
* @description 注销
|
||||
*/
|
||||
async function logout () {
|
||||
await SYS_USER_LOGOUT({ refresh: util.cookies.get('refresh') }).then(() => {
|
||||
// 删除cookie
|
||||
util.cookies.remove('token')
|
||||
util.cookies.remove('uuid')
|
||||
util.cookies.remove('refresh')
|
||||
})
|
||||
async function logout() {
|
||||
await SYS_USER_LOGOUT({ refresh: util.cookies.get("refresh") }).then(
|
||||
() => {
|
||||
// 删除cookie
|
||||
util.cookies.remove("token");
|
||||
util.cookies.remove("uuid");
|
||||
util.cookies.remove("refresh");
|
||||
}
|
||||
);
|
||||
// 清空 vuex 用户信息
|
||||
await dispatch('d2admin/user/set', {}, { root: true })
|
||||
store.commit('d2admin/menu/asideSet', []) // 设置侧边栏菜单
|
||||
store.commit('d2admin/search/init', []) // 设置搜索
|
||||
sessionStorage.removeItem('menuData')
|
||||
await dispatch("d2admin/user/set", {}, { root: true });
|
||||
store.commit("d2admin/menu/asideSet", []); // 设置侧边栏菜单
|
||||
store.commit("d2admin/search/init", []); // 设置搜索
|
||||
sessionStorage.removeItem("menuData");
|
||||
|
||||
store.dispatch('d2admin/db/databaseClear')
|
||||
store.dispatch("d2admin/db/databaseClear");
|
||||
|
||||
// 跳转路由
|
||||
router.push({ name: 'login' })
|
||||
router.go(0)
|
||||
router.push({ name: "login" });
|
||||
router.go(0);
|
||||
}
|
||||
// 判断是否需要确认
|
||||
if (confirm) {
|
||||
commit('d2admin/gray/set', true, { root: true })
|
||||
MessageBox.confirm('确定要注销当前用户吗', '注销用户', { type: 'warning' })
|
||||
commit("d2admin/gray/set", true, { root: true });
|
||||
MessageBox.confirm("确定要注销当前用户吗", "注销用户", {
|
||||
type: "warning",
|
||||
})
|
||||
.then(() => {
|
||||
commit('d2admin/gray/set', false, { root: true })
|
||||
logout()
|
||||
commit("d2admin/gray/set", false, { root: true });
|
||||
logout();
|
||||
})
|
||||
.catch(() => {
|
||||
commit('d2admin/gray/set', false, { root: true })
|
||||
Message({ message: '取消注销操作' })
|
||||
})
|
||||
commit("d2admin/gray/set", false, { root: true });
|
||||
Message({ message: "取消注销操作" });
|
||||
});
|
||||
} else {
|
||||
logout()
|
||||
logout();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @description 用户登录后从持久化数据加载一系列的设置
|
||||
* @param {Object} context
|
||||
*/
|
||||
async load ({ dispatch }) {
|
||||
* @description 用户登录后从持久化数据加载一系列的设置
|
||||
* @param {Object} context
|
||||
*/
|
||||
async load({ dispatch }) {
|
||||
// 加载用户名
|
||||
await dispatch('d2admin/user/load', null, { root: true })
|
||||
await dispatch("d2admin/user/load", null, { root: true });
|
||||
// 加载主题
|
||||
await dispatch('d2admin/theme/load', null, { root: true })
|
||||
await dispatch("d2admin/theme/load", null, { root: true });
|
||||
// 加载页面过渡效果设置
|
||||
await dispatch('d2admin/transition/load', null, { root: true })
|
||||
await dispatch("d2admin/transition/load", null, { root: true });
|
||||
// 持久化数据加载上次退出时的多页列表
|
||||
await dispatch('d2admin/page/openedLoad', null, { root: true })
|
||||
await dispatch("d2admin/page/openedLoad", null, { root: true });
|
||||
// 持久化数据加载侧边栏配置
|
||||
await dispatch('d2admin/menu/asideLoad', null, { root: true })
|
||||
await dispatch("d2admin/menu/asideLoad", null, { root: true });
|
||||
// 持久化数据加载全局尺寸
|
||||
await dispatch('d2admin/size/load', null, { root: true })
|
||||
await dispatch("d2admin/size/load", null, { root: true });
|
||||
// 持久化数据加载颜色设置
|
||||
await dispatch('d2admin/color/load', null, { root: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
await dispatch("d2admin/color/load", null, { root: true });
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,76 +1,71 @@
|
|||
import { get } from 'lodash'
|
||||
import setting from '@/setting.js'
|
||||
import { get } from "lodash";
|
||||
import setting from "@/setting.js";
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
// 主题
|
||||
list: get(setting, 'theme.list', []),
|
||||
list: get(setting, "theme.list", []),
|
||||
// 现在激活的主题 这应该是一个名字 不是对象
|
||||
activeName: get(setting, 'theme.list[0].name', 'd2')
|
||||
activeName: get(setting, "theme.list[0].name", "d2"),
|
||||
},
|
||||
getters: {
|
||||
/**
|
||||
* @description 返回当前的主题信息 不是一个名字 而是当前激活主题的所有数据
|
||||
* @param {Object} state state
|
||||
*/
|
||||
activeSetting (state) {
|
||||
return state.list.find(theme => theme.name === state.activeName)
|
||||
}
|
||||
activeSetting(state) {
|
||||
return state.list.find((theme) => theme.name === state.activeName);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* @description 激活一个主题
|
||||
* @param {String} themeValue 需要激活的主题名称
|
||||
*/
|
||||
async set ({ state, commit, dispatch }, themeName) {
|
||||
async set({ state, commit, dispatch }, themeName) {
|
||||
// 检查这个主题在主题列表里是否存在
|
||||
state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name
|
||||
state.activeName = state.list.find((e) => e.name === themeName)
|
||||
? themeName
|
||||
: setting.defaultTheme;
|
||||
// 将 vuex 中的主题应用到 dom
|
||||
commit('dom')
|
||||
commit("dom");
|
||||
// 持久化
|
||||
await dispatch('d2admin/db/set', {
|
||||
dbName: 'sys',
|
||||
path: 'theme.activeName',
|
||||
value: state.activeName,
|
||||
user: true
|
||||
}, { root: true })
|
||||
await dispatch(
|
||||
"d2admin/db/set",
|
||||
{
|
||||
dbName: "sys",
|
||||
path: "theme.activeName",
|
||||
value: state.activeName,
|
||||
user: true,
|
||||
},
|
||||
{ root: true }
|
||||
);
|
||||
},
|
||||
/**
|
||||
* @description 从持久化数据加载主题设置 * @param {Object} context
|
||||
*/
|
||||
async load ({ state, commit, dispatch }) {
|
||||
async load({ state, commit, dispatch }) {
|
||||
// store 赋值
|
||||
const activeName = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
path: 'theme.activeName',
|
||||
defaultValue: state.list[0].name,
|
||||
user: true
|
||||
}, { root: true })
|
||||
const activeName = setting.defaultTheme;
|
||||
// 检查这个主题在主题列表里是否存在
|
||||
if (state.list.find(e => e.name === activeName)) {
|
||||
state.activeName = activeName
|
||||
if (state.list.find((e) => e.name === activeName)) {
|
||||
state.activeName = activeName;
|
||||
} else {
|
||||
state.activeName = state.list[0].name
|
||||
state.activeName = setting.defaultTheme;
|
||||
// 持久化
|
||||
await dispatch('d2admin/db/set', {
|
||||
dbName: 'sys',
|
||||
path: 'theme.activeName',
|
||||
value: state.activeName,
|
||||
user: true
|
||||
}, { root: true })
|
||||
}
|
||||
// 将 vuex 中的主题应用到 dom
|
||||
commit('dom')
|
||||
}
|
||||
commit("dom");
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* @description 将 vuex 中的主题应用到 dom
|
||||
* @param {Object} state state
|
||||
*/
|
||||
dom (state) {
|
||||
document.body.className = `theme-${state.activeName}`
|
||||
}
|
||||
}
|
||||
}
|
||||
dom(state) {
|
||||
document.body.className = `theme-${state.activeName}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -903,6 +903,13 @@
|
|||
core-js-pure "^3.20.2"
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@babel/runtime@^7.10.5", "@babel/runtime@^7.7.2":
|
||||
version "7.19.4"
|
||||
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.19.4.tgz#a42f814502ee467d55b38dd1c256f53a7b885c78"
|
||||
integrity sha512-EXpLCrk55f+cYqmHsSR+yD/0gAIMxxA9QK9lnQWzhMCvt+YmoBN7Zx94s++Kv0+unHk39vxNO8t+CMA2WSS3wA==
|
||||
dependencies:
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@babel/runtime@^7.11.0", "@babel/runtime@^7.11.2", "@babel/runtime@^7.8.4":
|
||||
version "7.17.9"
|
||||
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.9.tgz#d19fbf802d01a8cb6cf053a64e472d42c434ba72"
|
||||
|
@ -6156,6 +6163,13 @@ import-from@^2.1.0:
|
|||
dependencies:
|
||||
resolve-from "^3.0.0"
|
||||
|
||||
import-html-entry@^1.14.0:
|
||||
version "1.14.0"
|
||||
resolved "https://registry.npmjs.org/import-html-entry/-/import-html-entry-1.14.0.tgz#9a05928373bb7e9362cd8dd428a82387a87524ff"
|
||||
integrity sha512-CQQMV+2rxHCLMSXsajV1cjT1g6xi3ujMAPnGwR96xHaN5/JEVIOUGkM7LDRn73dk8E8NaHmOf3rvPPExPPe1xw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.7.2"
|
||||
|
||||
import-local@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/import-local/-/import-local-2.0.0.tgz#55070be38a5993cf18ef6db7e961f5bee5c5a09d"
|
||||
|
@ -9295,6 +9309,16 @@ q@^1.1.2:
|
|||
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
|
||||
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
|
||||
|
||||
qiankun@^2.7.2:
|
||||
version "2.8.3"
|
||||
resolved "https://registry.npmjs.org/qiankun/-/qiankun-2.8.3.tgz#752326bf655b710844362ee691a5f332160cd53c"
|
||||
integrity sha512-bq09dwm29NybhoG8UI8z6fdY5weaQ2l1CTxZcnVIbWLVzpzNyoebnnBTGMuZyRsoSY3gflO96RC2jK7ARiOGvA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.10.5"
|
||||
import-html-entry "^1.14.0"
|
||||
lodash "^4.17.11"
|
||||
single-spa "^5.9.2"
|
||||
|
||||
qiniu-js@^2.5.4:
|
||||
version "2.5.5"
|
||||
resolved "https://registry.yarnpkg.com/qiniu-js/-/qiniu-js-2.5.5.tgz#77d295f222620f9377d6148f3f757d189a1e4977"
|
||||
|
@ -10059,6 +10083,11 @@ simple-swizzle@^0.2.2:
|
|||
dependencies:
|
||||
is-arrayish "^0.3.1"
|
||||
|
||||
single-spa@^5.9.2:
|
||||
version "5.9.4"
|
||||
resolved "https://registry.npmjs.org/single-spa/-/single-spa-5.9.4.tgz#2a995b0784867a3f60ceb458de295ee67f045077"
|
||||
integrity sha512-QkEoh0AzGuU82qnbUUk0ydF78QbU5wMKqKKJn7uUQfBiOYlRQEfIOpLM4m23Sab+kTOLI1kbYhYeiQ7fX5KVVw==
|
||||
|
||||
sisteransi@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
|
||||
|
@ -11340,6 +11369,11 @@ vue-i18n@^8.15.1, vue-i18n@^8.17.0:
|
|||
resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.27.1.tgz#fe660f6c14793ae404d6a715875d772594a3324f"
|
||||
integrity sha512-lWrGm4F25qReJ7XxSnFVb2h3PfW54ldnM4C+YLBGGJ75+Myt/kj4hHSTKqsyDLamvNYpvINMicSOdW+7yuqgIQ==
|
||||
|
||||
vue-infinite-scroll@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.npmjs.org/vue-infinite-scroll/-/vue-infinite-scroll-2.0.2.tgz#ca37a91fe92ee0ad3b74acf8682c00917144b711"
|
||||
integrity sha512-n+YghR059YmciANGJh9SsNWRi1YZEBVlODtmnb/12zI+4R72QZSWd+EuZ5mW6auEo/yaJXgxzwsuhvALVnm73A==
|
||||
|
||||
vue-jest@^3.0.5:
|
||||
version "3.0.7"
|
||||
resolved "https://registry.yarnpkg.com/vue-jest/-/vue-jest-3.0.7.tgz#a6d29758a5cb4d750f5d1242212be39be4296a33"
|
||||
|
|
Loading…
Reference in New Issue