feat:小程序菜单管理
This commit is contained in:
1 parent
978877d86b
commit
3783e74934
4 files changed
+413
-74
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import request from "/@/utils/request"
|
||||
|
||||
export function fetchList(query?: Object) {
|
||||
return request({
|
||||
url: "/app/app-menu/page",
|
||||
method: "get",
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
export function addObj(obj?: Object) {
|
||||
return request({
|
||||
url: "/app/app-menu",
|
||||
method: "post",
|
||||
data: obj,
|
||||
})
|
||||
}
|
||||
|
||||
export function getObj(id?: string) {
|
||||
return request({
|
||||
url: "/app/app-menu/" + id,
|
||||
method: "get",
|
||||
})
|
||||
}
|
||||
|
||||
export function delObjs(ids?: Object) {
|
||||
return request({
|
||||
url: "/app/app-menu",
|
||||
method: "delete",
|
||||
data: ids,
|
||||
})
|
||||
}
|
||||
|
||||
export function putObj(obj?: Object) {
|
||||
return request({
|
||||
url: "/app/app-menu",
|
||||
method: "put",
|
||||
data: obj,
|
||||
})
|
||||
}
|
||||
+73
-74
@@ -1,171 +1,170 @@
|
||||
import request from '/@/utils/request';
|
||||
import {Session} from '/@/utils/storage';
|
||||
import {validateNull} from '/@/utils/validate';
|
||||
import {useUserInfo} from '/@/stores/userInfo';
|
||||
import other from '/@/utils/other';
|
||||
import request from "/@/utils/request"
|
||||
import { Session } from "/@/utils/storage"
|
||||
import { validateNull } from "/@/utils/validate"
|
||||
import { useUserInfo } from "/@/stores/userInfo"
|
||||
import other from "/@/utils/other"
|
||||
|
||||
/**
|
||||
* https://www.ietf.org/rfc/rfc6749.txt
|
||||
* OAuth 协议 4.3.1 要求格式为 form 而不是 JSON 注意!
|
||||
*/
|
||||
const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
||||
const FORM_CONTENT_TYPE = "application/x-www-form-urlencoded"
|
||||
|
||||
// 登录方式
|
||||
export enum LoginTypeEnum {
|
||||
PASSWORD,
|
||||
MOBILE,
|
||||
REGISTER,
|
||||
EXPIRE
|
||||
EXPIRE,
|
||||
}
|
||||
|
||||
// 登录错误信息
|
||||
export enum LoginErrorEnum {
|
||||
CREDENTIALS_EXPIRED = 'credentials_expired'// 密码过期
|
||||
CREDENTIALS_EXPIRED = "credentials_expired", // 密码过期
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param data
|
||||
*/
|
||||
export const login = (data: any) => {
|
||||
const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_PASSWORD_CLIENT);
|
||||
Session.set('basicAuth', basicAuth);
|
||||
const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_PASSWORD_CLIENT)
|
||||
Session.set("basicAuth", basicAuth)
|
||||
// 密码加密
|
||||
const encPassword = other.encryption(data.password, import.meta.env.VITE_PWD_ENC_KEY);
|
||||
const { username, randomStr, code, grant_type, scope } = data;
|
||||
const encPassword = other.encryption(data.password, import.meta.env.VITE_PWD_ENC_KEY)
|
||||
const { username, randomStr, code, grant_type, scope } = data
|
||||
return request({
|
||||
url: '/auth/oauth2/token',
|
||||
method: 'post',
|
||||
url: "/auth/oauth2/token",
|
||||
method: "post",
|
||||
params: { username, randomStr, code, grant_type, scope },
|
||||
data: { password: encPassword },
|
||||
headers: {
|
||||
skipToken: true,
|
||||
Authorization: basicAuth,
|
||||
'Content-Type': FORM_CONTENT_TYPE,
|
||||
"Content-Type": FORM_CONTENT_TYPE,
|
||||
},
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
export const loginByMobile = (mobile: any, code: any) => {
|
||||
const grant_type = 'mobile';
|
||||
const scope = 'server';
|
||||
const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_MOBILE_CLIENT);
|
||||
Session.set('basicAuth', basicAuth);
|
||||
const grant_type = "mobile"
|
||||
const scope = "server"
|
||||
const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_MOBILE_CLIENT)
|
||||
Session.set("basicAuth", basicAuth)
|
||||
|
||||
return request({
|
||||
url: '/auth/oauth2/token',
|
||||
url: "/auth/oauth2/token",
|
||||
headers: {
|
||||
skipToken: true,
|
||||
Authorization: basicAuth,
|
||||
'Content-Type': FORM_CONTENT_TYPE,
|
||||
"Content-Type": FORM_CONTENT_TYPE,
|
||||
},
|
||||
method: 'post',
|
||||
params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope },
|
||||
});
|
||||
};
|
||||
method: "post",
|
||||
params: { mobile: "SMS@" + mobile, code: code, grant_type, scope },
|
||||
})
|
||||
}
|
||||
|
||||
export const loginBySocial = (state: string, code: string) => {
|
||||
const grant_type = 'mobile';
|
||||
const scope = 'server';
|
||||
const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_SOCIAL_CLIENT);
|
||||
Session.set('basicAuth', basicAuth);
|
||||
const grant_type = "mobile"
|
||||
const scope = "server"
|
||||
const basicAuth = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_SOCIAL_CLIENT)
|
||||
Session.set("basicAuth", basicAuth)
|
||||
|
||||
return request({
|
||||
url: '/auth/oauth2/token',
|
||||
url: "/auth/oauth2/token",
|
||||
headers: {
|
||||
skipToken: true,
|
||||
Authorization: basicAuth,
|
||||
'Content-Type': FORM_CONTENT_TYPE,
|
||||
"Content-Type": FORM_CONTENT_TYPE,
|
||||
},
|
||||
method: 'post',
|
||||
params: { mobile: state + '@' + code, code: code, grant_type, scope },
|
||||
});
|
||||
};
|
||||
method: "post",
|
||||
params: { mobile: state + "@" + code, code: code, grant_type, scope },
|
||||
})
|
||||
}
|
||||
|
||||
export const sendMobileCode = (mobile: string) => {
|
||||
return request({
|
||||
url: '/admin/sysMessage/send/smsCode',
|
||||
method: 'get',
|
||||
params: { mobile }
|
||||
});
|
||||
};
|
||||
url: "/admin/sysMessage/send/smsCode",
|
||||
method: "get",
|
||||
params: { mobile },
|
||||
})
|
||||
}
|
||||
|
||||
export const refreshTokenApi = (refresh_token: string) => {
|
||||
const grant_type = 'refresh_token';
|
||||
const scope = 'server';
|
||||
const grant_type = "refresh_token"
|
||||
const scope = "server"
|
||||
// 获取当前选中的 basic 认证信息
|
||||
const basicAuth = Session.get('basicAuth');
|
||||
const basicAuth = Session.get("basicAuth")
|
||||
|
||||
return request({
|
||||
url: '/auth/oauth2/token',
|
||||
url: "/auth/oauth2/token",
|
||||
headers: {
|
||||
skipToken: true,
|
||||
Authorization: basicAuth,
|
||||
'Content-Type': FORM_CONTENT_TYPE,
|
||||
"Content-Type": FORM_CONTENT_TYPE,
|
||||
},
|
||||
method: 'post',
|
||||
method: "post",
|
||||
params: { refresh_token, grant_type, scope },
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验令牌,若有效期小于半小时自动续期
|
||||
* @param refreshLock
|
||||
*/
|
||||
export const checkToken = (refreshTime: number, refreshLock: boolean) => {
|
||||
const basicAuth = Session.get('basicAuth');
|
||||
const basicAuth = Session.get("basicAuth")
|
||||
request({
|
||||
url: '/auth/token/check_token',
|
||||
url: "/auth/token/check_token",
|
||||
headers: {
|
||||
skipToken: true,
|
||||
Authorization: basicAuth,
|
||||
'Content-Type': FORM_CONTENT_TYPE,
|
||||
"Content-Type": FORM_CONTENT_TYPE,
|
||||
},
|
||||
method: 'get',
|
||||
method: "get",
|
||||
params: { token: Session.getToken() },
|
||||
})
|
||||
.then((response) => {
|
||||
if (validateNull(response) || response.code === 1) {
|
||||
clearInterval(refreshTime);
|
||||
return;
|
||||
clearInterval(refreshTime)
|
||||
return
|
||||
}
|
||||
const expire = Date.parse(response.data.expiresAt);
|
||||
const expire = Date.parse(response.data.expiresAt)
|
||||
if (expire) {
|
||||
const expiredPeriod = expire - new Date().getTime();
|
||||
const expiredPeriod = expire - new Date().getTime()
|
||||
//小于半小时自动续约
|
||||
if (expiredPeriod <= 30 * 60 * 1000) {
|
||||
if (!refreshLock) {
|
||||
refreshLock = true;
|
||||
refreshLock = true
|
||||
useUserInfo()
|
||||
.refreshToken()
|
||||
.catch(() => {
|
||||
clearInterval(refreshTime);
|
||||
});
|
||||
refreshLock = false;
|
||||
clearInterval(refreshTime)
|
||||
})
|
||||
refreshLock = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// 发生异常关闭定时器
|
||||
clearInterval(refreshTime);
|
||||
});
|
||||
};
|
||||
clearInterval(refreshTime)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export const getUserInfo = () => {
|
||||
return request({
|
||||
url: '/admin/user/info',
|
||||
method: 'get',
|
||||
});
|
||||
};
|
||||
url: "/admin/user/info",
|
||||
method: "get",
|
||||
})
|
||||
}
|
||||
|
||||
export const logout = () => {
|
||||
return request({
|
||||
url: '/auth/token/logout',
|
||||
method: 'delete',
|
||||
});
|
||||
};
|
||||
url: "/auth/token/logout",
|
||||
method: "delete",
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible" :close-on-click-modal="false" draggable>
|
||||
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="平台" prop="platform">
|
||||
<dict-select v-model="form.platform" dict-code="app_menu_platform" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="菜单类型" prop="type">
|
||||
<dict-select v-model="form.type" dict-code="app_menu_type" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24" class="mb20">
|
||||
<el-form-item label="图标" prop="icon">
|
||||
<upload-img v-model:imageUrl="form.icon" height="60px" width="60px" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24" class="mb20">
|
||||
<el-form-item label="页面路径" prop="page">
|
||||
<el-input v-model="form.page" placeholder="请输入页面路径" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="页面标题" prop="title">
|
||||
<el-input v-model="form.title" placeholder="请输入页面标题" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item label="是否显示" prop="visible">
|
||||
<dict-select v-model="form.visible" dict-code="yes_no_type" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" class="mb20">
|
||||
<el-form-item prop="sort">
|
||||
<template #label>排序
|
||||
<tip content="越大越在前" />
|
||||
</template>
|
||||
<el-input-number v-model="form.sort" placeholder="请输入排序(越大越在前)" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="AppMenuDialog">
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { useMessage } from "/@/hooks/message";
|
||||
import * as appMenuApi from "/@/api/app/app-menu"
|
||||
const emit = defineEmits(['refresh']);
|
||||
|
||||
// 定义变量内容
|
||||
const dataFormRef = ref();
|
||||
const visible = ref(false)
|
||||
const loading = ref(false)
|
||||
// 定义字典
|
||||
|
||||
// 提交表单数据
|
||||
const form = reactive({
|
||||
id: '',
|
||||
platform: '',
|
||||
type: '',
|
||||
icon: '',
|
||||
page: '',
|
||||
title: '',
|
||||
visible: '',
|
||||
sort: '',
|
||||
});
|
||||
|
||||
// 定义校验规则
|
||||
const dataRules = ref({
|
||||
platform: [{ required: true, message: "请选择平台", trigger: "change" }],
|
||||
type: [{ required: true, message: "请选择菜单类型", trigger: "change" }],
|
||||
page: [{ required: true, message: "页面路径不能为空", trigger: "blur" }],
|
||||
title: [{ required: true, message: "页面标题不能为空", trigger: "blur" }],
|
||||
visible: [{ required: true, message: "请选择是否显示", trigger: "change" }],
|
||||
sort: [{ required: true, message: "排序不能为空", trigger: "change" }],
|
||||
})
|
||||
|
||||
// 打开弹窗
|
||||
const openDialog = (id: string) => {
|
||||
visible.value = true
|
||||
form.id = ''
|
||||
|
||||
// 重置表单数据
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
// 获取appMenu信息
|
||||
if (id) {
|
||||
form.id = id
|
||||
getappMenuData(id)
|
||||
}
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = async () => {
|
||||
const valid = await dataFormRef.value.validate().catch(() => { });
|
||||
if (!valid) return false;
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
form.id ? await appMenuApi.putObj(form) : await appMenuApi.addObj(form);
|
||||
useMessage().success(form.id ? '修改成功' : '添加成功');
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 初始化表单数据
|
||||
const getappMenuData = (id: string) => {
|
||||
// 获取数据
|
||||
loading.value = true
|
||||
appMenuApi.getObj(id).then((res: any) => {
|
||||
Object.assign(form, res.data)
|
||||
}).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
};
|
||||
|
||||
// 暴露变量
|
||||
defineExpose({
|
||||
openDialog
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,154 @@
|
||||
<template>
|
||||
<div class="layout-padding">
|
||||
<div class="layout-padding-auto layout-padding-view">
|
||||
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
|
||||
<el-row>
|
||||
<el-form-item style="width: 300px" label="页面标题" prop="title">
|
||||
<el-input v-model="state.queryForm.title" placeholder="请输入页面标题" />
|
||||
</el-form-item>
|
||||
<el-form-item style="width: 300px" label="平台" prop="platform">
|
||||
<dict-select v-model="state.queryForm.platform" dict-code="app_menu_platform" />
|
||||
</el-form-item>
|
||||
<el-form-item style="width: 300px" label="菜单类型" prop="type">
|
||||
<dict-select v-model="state.queryForm.type" dict-code="app_menu_type" />
|
||||
</el-form-item>
|
||||
<el-form-item style="width: 300px" label="是否显示" prop="visible">
|
||||
<dict-select v-model="state.queryForm.visible" dict-code="yes_no_type" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button icon="Search" type="primary" @click="getDataList">
|
||||
{{ $t("common.queryBtn") }}
|
||||
</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">
|
||||
{{ $t("common.resetBtn") }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<el-row>
|
||||
<div class="mb8" style="width: 100%">
|
||||
<el-button icon="folder-add" type="primary" class="ml10" @click="formDialogRef.openDialog()"
|
||||
v-auth="'app_appMenu_add'">
|
||||
新 增
|
||||
</el-button>
|
||||
<el-button plain :disabled="multiple" icon="Delete" type="primary" v-auth="'app_appMenu_del'"
|
||||
@click="handleDelete(selectObjs)">
|
||||
删除
|
||||
</el-button>
|
||||
<right-toolbar v-model:showSearch="showSearch" :export="'app_appMenu_export'" @exportExcel="exportExcel"
|
||||
class="ml10 mr20" style="float: right;" @queryTable="getDataList"></right-toolbar>
|
||||
</div>
|
||||
</el-row>
|
||||
<el-table :data="state.dataList" v-loading="state.loading" border :cell-style="tableStyle.cellStyle"
|
||||
:header-cell-style="tableStyle.headerCellStyle" @selection-change="selectionChangHandle"
|
||||
@sort-change="sortChangeHandle">
|
||||
<el-table-column type="selection" width="40" align="center" />
|
||||
<el-table-column type="index" label="#" width="40" />
|
||||
<el-table-column prop="platform" label="平台">
|
||||
<template #default="{ row }">
|
||||
<dict-tag :options="app_menu_platform" :value="row.platform" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="菜单类型">
|
||||
<template #default="{ row }">
|
||||
<dict-tag :options="app_menu_type" :value="row.type" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="icon" label="图标" />
|
||||
<el-table-column prop="page" label="页面路径" width="500" show-overflow-tooltip />
|
||||
<el-table-column prop="title" label="页面标题" />
|
||||
<el-table-column prop="visible" label="是否显示">
|
||||
<template #default="{ row }">
|
||||
<dict-tag :options="yes_no_type" :value="row.visible" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sort" label="排序" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-button icon="edit-pen" text type="primary" v-auth="'app_appMenu_edit'"
|
||||
@click="formDialogRef.openDialog(row.id)">编辑</el-button>
|
||||
<el-button icon="delete" text type="primary" v-auth="'app_appMenu_del'"
|
||||
@click="handleDelete([row.id])">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
|
||||
</div>
|
||||
|
||||
<!-- 编辑、新增 -->
|
||||
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="systemAppMenu">
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import * as appMenuApi from "/@/api/app/app-menu"
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message";
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
|
||||
// 引入组件
|
||||
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
|
||||
// 定义查询字典
|
||||
const { app_menu_platform, app_menu_type, yes_no_type } = useDict('app_menu_platform', 'app_menu_type', 'yes_no_type')
|
||||
// 定义变量内容
|
||||
const formDialogRef = ref()
|
||||
// 搜索变量
|
||||
const queryRef = ref()
|
||||
const showSearch = ref(true)
|
||||
// 多选变量
|
||||
const selectObjs = ref([]) as any
|
||||
const multiple = ref(true)
|
||||
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: {},
|
||||
pageList: appMenuApi.fetchList
|
||||
})
|
||||
|
||||
// table hook
|
||||
const {
|
||||
getDataList,
|
||||
currentChangeHandle,
|
||||
sizeChangeHandle,
|
||||
sortChangeHandle,
|
||||
downBlobFile,
|
||||
tableStyle
|
||||
} = useTable(state)
|
||||
|
||||
// 清空搜索条件
|
||||
const resetQuery = () => {
|
||||
// 清空搜索条件
|
||||
queryRef.value?.resetFields()
|
||||
// 清空多选
|
||||
selectObjs.value = []
|
||||
getDataList()
|
||||
}
|
||||
|
||||
// 导出excel
|
||||
const exportExcel = () => {
|
||||
downBlobFile('/app/appMenu/export', Object.assign(state.queryForm, { ids: selectObjs }), 'appMenu.xlsx')
|
||||
}
|
||||
|
||||
// 多选事件
|
||||
const selectionChangHandle = (objs: { id: string }[]) => {
|
||||
selectObjs.value = objs.map(({ id }) => id);
|
||||
multiple.value = !objs.length;
|
||||
};
|
||||
|
||||
// 删除操作
|
||||
const handleDelete = async (ids: string[]) => {
|
||||
try {
|
||||
await useMessageBox().confirm('此操作将永久删除');
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await appMenuApi.delObjs(ids);
|
||||
getDataList();
|
||||
useMessage().success('删除成功');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in new issue
Block a user