update 调整代码格式

This commit is contained in:
疯狂的狮子Li
2023-04-03 00:05:09 +08:00
parent 8b01bfd2a0
commit 1595cb282a
194 changed files with 12184 additions and 12267 deletions

View File

@ -1,60 +1,60 @@
import useUserStore from '@/store/modules/user';
const authPermission = (permission: string): boolean => {
const all_permission = '*:*:*';
const permissions: string[] = useUserStore().permissions;
if (permission && permission.length > 0) {
return permissions.some((v) => {
return all_permission === v || v === permission;
});
} else {
return false;
}
const all_permission = '*:*:*';
const permissions: string[] = useUserStore().permissions;
if (permission && permission.length > 0) {
return permissions.some((v) => {
return all_permission === v || v === permission;
});
} else {
return false;
}
};
const authRole = (role: string): boolean => {
const super_admin = 'admin';
const roles = useUserStore().roles;
if (role && role.length > 0) {
return roles.some((v) => {
return super_admin === v || v === role;
});
} else {
return false;
}
const super_admin = 'admin';
const roles = useUserStore().roles;
if (role && role.length > 0) {
return roles.some((v) => {
return super_admin === v || v === role;
});
} else {
return false;
}
};
export default {
// 验证用户是否具备某权限
hasPermi(permission: string): boolean {
return authPermission(permission);
},
// 验证用户是否含有指定权限,只需包含其中一个
hasPermiOr(permissions: string[]): boolean {
return permissions.some((item) => {
return authPermission(item);
});
},
// 验证用户是否含有指定权限,必须全部拥有
hasPermiAnd(permissions: string[]): boolean {
return permissions.every((item) => {
return authPermission(item);
});
},
// 验证用户是否具备某角色
hasRole(role: string): boolean {
return authRole(role);
},
// 验证用户是否含有指定角色,只需包含其中一个
hasRoleOr(roles: string[]): boolean {
return roles.some((item) => {
return authRole(item);
});
},
// 验证用户是否含有指定角色,必须全部拥有
hasRoleAnd(roles: string[]): boolean {
return roles.every((item) => {
return authRole(item);
});
}
// 验证用户是否具备某权限
hasPermi(permission: string): boolean {
return authPermission(permission);
},
// 验证用户是否含有指定权限,只需包含其中一个
hasPermiOr(permissions: string[]): boolean {
return permissions.some((item) => {
return authPermission(item);
});
},
// 验证用户是否含有指定权限,必须全部拥有
hasPermiAnd(permissions: string[]): boolean {
return permissions.every((item) => {
return authPermission(item);
});
},
// 验证用户是否具备某角色
hasRole(role: string): boolean {
return authRole(role);
},
// 验证用户是否含有指定角色,只需包含其中一个
hasRoleOr(roles: string[]): boolean {
return roles.some((item) => {
return authRole(item);
});
},
// 验证用户是否含有指定角色,必须全部拥有
hasRoleAnd(roles: string[]): boolean {
return roles.every((item) => {
return authRole(item);
});
}
};

View File

@ -1,77 +1,77 @@
const sessionCache = {
set(key: string, value: any) {
if (!sessionStorage) {
return;
}
if (key != null && value != null) {
sessionStorage.setItem(key, value);
}
},
get(key: string) {
if (!sessionStorage) {
return null;
}
if (key == null) {
return null;
}
return sessionStorage.getItem(key);
},
setJSON(key: string, jsonValue: any) {
if (jsonValue != null) {
this.set(key, JSON.stringify(jsonValue));
}
},
getJSON(key: string) {
const value = this.get(key);
if (value != null) {
return JSON.parse(value);
}
},
remove(key: string) {
sessionStorage.removeItem(key);
}
set(key: string, value: any) {
if (!sessionStorage) {
return;
}
if (key != null && value != null) {
sessionStorage.setItem(key, value);
}
},
get(key: string) {
if (!sessionStorage) {
return null;
}
if (key == null) {
return null;
}
return sessionStorage.getItem(key);
},
setJSON(key: string, jsonValue: any) {
if (jsonValue != null) {
this.set(key, JSON.stringify(jsonValue));
}
},
getJSON(key: string) {
const value = this.get(key);
if (value != null) {
return JSON.parse(value);
}
},
remove(key: string) {
sessionStorage.removeItem(key);
}
};
const localCache = {
set(key: string, value: any) {
if (!localStorage) {
return;
}
if (key != null && value != null) {
localStorage.setItem(key, value);
}
},
get(key: string) {
if (!localStorage) {
return null;
}
if (key == null) {
return null;
}
return localStorage.getItem(key);
},
setJSON(key: string, jsonValue: any) {
if (jsonValue != null) {
this.set(key, JSON.stringify(jsonValue));
}
},
getJSON(key: string) {
const value = this.get(key);
if (value != null) {
return JSON.parse(value);
}
},
remove(key: string) {
localStorage.removeItem(key);
}
set(key: string, value: any) {
if (!localStorage) {
return;
}
if (key != null && value != null) {
localStorage.setItem(key, value);
}
},
get(key: string) {
if (!localStorage) {
return null;
}
if (key == null) {
return null;
}
return localStorage.getItem(key);
},
setJSON(key: string, jsonValue: any) {
if (jsonValue != null) {
this.set(key, JSON.stringify(jsonValue));
}
},
getJSON(key: string) {
const value = this.get(key);
if (value != null) {
return JSON.parse(value);
}
},
remove(key: string) {
localStorage.removeItem(key);
}
};
export default {
/**
* 会话级缓存
*/
session: sessionCache,
/**
* 本地缓存
*/
local: localCache
/**
* 会话级缓存
*/
session: sessionCache,
/**
* 本地缓存
*/
local: localCache
};

View File

@ -8,53 +8,53 @@ import { LoadingInstance } from 'element-plus/es/components/loading/src/loading'
const baseURL = import.meta.env.VITE_APP_BASE_API;
let downloadLoadingInstance: LoadingInstance;
export default {
async oss(ossId: string | number) {
const url = baseURL + '/system/oss/download/' + ossId;
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
try {
const res = await axios({
method: 'get',
url: url,
responseType: 'blob',
headers: { Authorization: 'Bearer ' + getToken() }
});
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data], { type: 'application/octet-stream' });
FileSaver.saveAs(blob, decodeURIComponent(res.headers['download-filename'] as string));
} else {
this.printErrMsg(res.data);
}
downloadLoadingInstance.close();
} catch (r) {
console.error(r);
ElMessage.error('下载文件出现错误,请联系管理员!');
downloadLoadingInstance.close();
}
},
async zip(url: string, name: string) {
url = baseURL + url;
const res = await axios({
method: 'get',
url: url,
responseType: 'blob',
headers: {
Authorization: 'Bearer ' + getToken(),
datasource: localStorage.getItem('dataName')
}
});
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data], { type: 'application/zip' });
FileSaver.saveAs(blob, name);
} else {
this.printErrMsg(res.data);
}
},
async printErrMsg(data: any) {
const resText = await data.text();
const rspObj = JSON.parse(resText);
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
ElMessage.error(errMsg);
}
async oss(ossId: string | number) {
const url = baseURL + '/system/oss/download/' + ossId;
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
try {
const res = await axios({
method: 'get',
url: url,
responseType: 'blob',
headers: { Authorization: 'Bearer ' + getToken() }
});
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data], { type: 'application/octet-stream' });
FileSaver.saveAs(blob, decodeURIComponent(res.headers['download-filename'] as string));
} else {
this.printErrMsg(res.data);
}
downloadLoadingInstance.close();
} catch (r) {
console.error(r);
ElMessage.error('下载文件出现错误,请联系管理员!');
downloadLoadingInstance.close();
}
},
async zip(url: string, name: string) {
url = baseURL + url;
const res = await axios({
method: 'get',
url: url,
responseType: 'blob',
headers: {
Authorization: 'Bearer ' + getToken(),
datasource: localStorage.getItem('dataName')
}
});
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data], { type: 'application/zip' });
FileSaver.saveAs(blob, name);
} else {
this.printErrMsg(res.data);
}
},
async printErrMsg(data: any) {
const resText = await data.text();
const rspObj = JSON.parse(resText);
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
ElMessage.error(errMsg);
}
};

View File

@ -7,18 +7,18 @@ import auth from './auth';
import { App } from 'vue';
export default function installPlugin(app: App) {
// 页签操作
app.config.globalProperties.$tab = tab;
// 页签操作
app.config.globalProperties.$tab = tab;
// 模态框对象
app.config.globalProperties.$modal = modal;
// 模态框对象
app.config.globalProperties.$modal = modal;
// 缓存对象
app.config.globalProperties.$cache = cache;
// 缓存对象
app.config.globalProperties.$cache = cache;
// 下载文件
app.config.globalProperties.$download = download;
// 下载文件
app.config.globalProperties.$download = download;
// 认证对象
app.config.globalProperties.$auth = auth;
// 认证对象
app.config.globalProperties.$auth = auth;
}

View File

@ -2,80 +2,80 @@ import { ElMessage, ElMessageBox, ElNotification, ElLoading, MessageBoxData } fr
import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
let loadingInstance: LoadingInstance;
export default {
// 消息提示
msg(content: string) {
ElMessage.info(content);
},
// 错误消息
msgError(content: string) {
ElMessage.error(content);
},
// 成功消息
msgSuccess(content: string) {
ElMessage.success(content);
},
// 警告消息
msgWarning(content: string) {
ElMessage.warning(content);
},
// 弹出提示
alert(content: string) {
ElMessageBox.alert(content, '系统提示');
},
// 错误提示
alertError(content: string) {
ElMessageBox.alert(content, '系统提示', { type: 'error' });
},
// 成功提示
alertSuccess(content: string, s: string, p: { dangerouslyUseHTMLString: boolean }) {
ElMessageBox.alert(content, '系统提示', { type: 'success' });
},
// 警告提示
alertWarning(content: string) {
ElMessageBox.alert(content, '系统提示', { type: 'warning' });
},
// 通知提示
notify(content: string) {
ElNotification.info(content);
},
// 错误通知
notifyError(content: string) {
ElNotification.error(content);
},
// 成功通知
notifySuccess(content: string) {
ElNotification.success(content);
},
// 警告通知
notifyWarning(content: string) {
ElNotification.warning(content);
},
// 确认窗体
confirm(content: string): Promise<MessageBoxData> {
return ElMessageBox.confirm(content, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
},
// 提交内容
prompt(content: string) {
return ElMessageBox.prompt(content, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
},
// 打开遮罩层
loading(content: string) {
loadingInstance = ElLoading.service({
lock: true,
text: content,
background: 'rgba(0, 0, 0, 0.7)'
});
},
// 关闭遮罩层
closeLoading() {
loadingInstance.close();
}
// 消息提示
msg(content: string) {
ElMessage.info(content);
},
// 错误消息
msgError(content: string) {
ElMessage.error(content);
},
// 成功消息
msgSuccess(content: string) {
ElMessage.success(content);
},
// 警告消息
msgWarning(content: string) {
ElMessage.warning(content);
},
// 弹出提示
alert(content: string) {
ElMessageBox.alert(content, '系统提示');
},
// 错误提示
alertError(content: string) {
ElMessageBox.alert(content, '系统提示', { type: 'error' });
},
// 成功提示
alertSuccess(content: string, s: string, p: { dangerouslyUseHTMLString: boolean }) {
ElMessageBox.alert(content, '系统提示', { type: 'success' });
},
// 警告提示
alertWarning(content: string) {
ElMessageBox.alert(content, '系统提示', { type: 'warning' });
},
// 通知提示
notify(content: string) {
ElNotification.info(content);
},
// 错误通知
notifyError(content: string) {
ElNotification.error(content);
},
// 成功通知
notifySuccess(content: string) {
ElNotification.success(content);
},
// 警告通知
notifyWarning(content: string) {
ElNotification.warning(content);
},
// 确认窗体
confirm(content: string): Promise<MessageBoxData> {
return ElMessageBox.confirm(content, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
},
// 提交内容
prompt(content: string) {
return ElMessageBox.prompt(content, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
},
// 打开遮罩层
loading(content: string) {
loadingInstance = ElLoading.service({
lock: true,
text: content,
background: 'rgba(0, 0, 0, 0.7)'
});
},
// 关闭遮罩层
closeLoading() {
loadingInstance.close();
}
};

View File

@ -2,9 +2,9 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { App } from 'vue';
export default {
install: (app: App) => {
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component);
}
}
install: (app: App) => {
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component);
}
}
};

View File

@ -3,63 +3,63 @@ import router from '@/router';
import { TagView, RouteLocationRaw } from 'vue-router';
export default {
// 刷新当前tab页签
async refreshPage(obj: TagView): Promise<void> {
const { path, query, matched } = router.currentRoute.value;
if (obj === undefined) {
matched.forEach((m) => {
if (m.components && m.components.default && m.components.default.name) {
if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
obj = { name: m.components.default.name, path: path, query: query };
}
}
});
}
// prettier-ignore
await useTagsViewStore().delCachedView(obj)
router.replace({
path: '/redirect' + obj.path,
query: obj.query
});
},
// 关闭当前tab页签打开新页签
closeOpenPage(obj: RouteLocationRaw): void {
useTagsViewStore().delView(router.currentRoute.value);
if (obj !== undefined) {
router.push(obj);
}
},
// 关闭指定tab页签
async closePage(obj?: TagView): Promise<{ visitedViews: TagView[]; cachedViews: string[] } | any> {
if (obj === undefined) {
// prettier-ignore
const { lastPath } = await useTagsViewStore().delView(router.currentRoute.value) as any
return router.push(lastPath || '/index');
}
return useTagsViewStore().delView(obj);
},
// 关闭所有tab页签
closeAllPage() {
return useTagsViewStore().delAllViews();
},
// 关闭左侧tab页签
closeLeftPage(obj: TagView) {
return useTagsViewStore().delLeftTags(obj || router.currentRoute.value);
},
// 关闭右侧tab页签
closeRightPage(obj: TagView) {
return useTagsViewStore().delRightTags(obj || router.currentRoute.value);
},
// 关闭其他tab页签
closeOtherPage(obj: TagView) {
return useTagsViewStore().delOthersViews(obj || router.currentRoute.value);
},
// 打开tab页签
openPage(url: RouteLocationRaw) {
return router.push(url);
},
// 修改tab页签
updatePage(obj: TagView) {
return useTagsViewStore().updateVisitedView(obj);
}
// 刷新当前tab页签
async refreshPage(obj: TagView): Promise<void> {
const { path, query, matched } = router.currentRoute.value;
if (obj === undefined) {
matched.forEach((m) => {
if (m.components && m.components.default && m.components.default.name) {
if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
obj = { name: m.components.default.name, path: path, query: query };
}
}
});
}
// prettier-ignore
await useTagsViewStore().delCachedView(obj)
router.replace({
path: '/redirect' + obj.path,
query: obj.query
});
},
// 关闭当前tab页签打开新页签
closeOpenPage(obj: RouteLocationRaw): void {
useTagsViewStore().delView(router.currentRoute.value);
if (obj !== undefined) {
router.push(obj);
}
},
// 关闭指定tab页签
async closePage(obj?: TagView): Promise<{ visitedViews: TagView[]; cachedViews: string[] } | any> {
if (obj === undefined) {
// prettier-ignore
const { lastPath } = await useTagsViewStore().delView(router.currentRoute.value) as any
return router.push(lastPath || '/index');
}
return useTagsViewStore().delView(obj);
},
// 关闭所有tab页签
closeAllPage() {
return useTagsViewStore().delAllViews();
},
// 关闭左侧tab页签
closeLeftPage(obj: TagView) {
return useTagsViewStore().delLeftTags(obj || router.currentRoute.value);
},
// 关闭右侧tab页签
closeRightPage(obj: TagView) {
return useTagsViewStore().delRightTags(obj || router.currentRoute.value);
},
// 关闭其他tab页签
closeOtherPage(obj: TagView) {
return useTagsViewStore().delOthersViews(obj || router.currentRoute.value);
},
// 打开tab页签
openPage(url: RouteLocationRaw) {
return router.push(url);
},
// 修改tab页签
updatePage(obj: TagView) {
return useTagsViewStore().updateVisitedView(obj);
}
};