mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
Merge branch 'client_sync' into v2
# Conflicts: # packages/ui/certd-client/CHANGELOG.md # packages/ui/certd-client/package.json # packages/ui/certd-client/src/api/tools.ts # packages/ui/certd-client/src/components/index.ts # packages/ui/certd-client/src/main.ts # packages/ui/certd-client/src/plugin/fast-crud/index.tsx # packages/ui/certd-client/src/plugin/index.ts # packages/ui/certd-client/src/router/source/framework.ts # packages/ui/certd-client/src/store/modules/page.ts # packages/ui/certd-client/src/style/common.less # packages/ui/certd-client/src/utils/util.env.ts # packages/ui/certd-client/src/views/crud/form/independent/index.vue # packages/ui/certd-client/src/views/framework/register/index.vue # packages/ui/certd-client/vite.config.ts
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { request, requestForMock } from "/src/api/service";
|
||||
import { ColumnCompositionProps, CrudOptions, FastCrud, setLogger, useColumns, UseCrudProps, useTypes } from "@fast-crud/fast-crud";
|
||||
import { ColumnCompositionProps, CrudOptions, FastCrud, PageQuery, PageRes, setLogger, TransformResProps, useColumns, UseCrudProps, UserPageQuery, useTypes, useUi } from "@fast-crud/fast-crud";
|
||||
import "@fast-crud/fast-crud/dist/style.css";
|
||||
import { FsExtendsCopyable, FsExtendsEditor, FsExtendsJson, FsExtendsTime, FsExtendsUploader } from "@fast-crud/fast-extends";
|
||||
import { FsExtendsCopyable, FsExtendsEditor, FsExtendsJson, FsExtendsTime, FsExtendsUploader, FsUploaderS3SignedUrlType } from "@fast-crud/fast-extends";
|
||||
import "@fast-crud/fast-extends/dist/style.css";
|
||||
import UiAntdv from "@fast-crud/ui-antdv";
|
||||
import _ from "lodash-es";
|
||||
import { useCrudPermission } from "../permission";
|
||||
import { App } from "vue";
|
||||
import { GetSignedUrl } from "/@/views/crud/component/uploader/s3/api";
|
||||
import { notification } from "ant-design-vue";
|
||||
|
||||
function install(app: App, options: any = {}) {
|
||||
app.use(UiAntdv);
|
||||
@@ -14,7 +16,7 @@ function install(app: App, options: any = {}) {
|
||||
setLogger({ level: "info" });
|
||||
app.use(FastCrud, {
|
||||
i18n: options.i18n,
|
||||
async dictRequest({ url }) {
|
||||
async dictRequest({ url }: any) {
|
||||
if (url && url.startsWith("/mock")) {
|
||||
//如果是crud开头的dict请求视为mock
|
||||
return await requestForMock({ url, method: "post" });
|
||||
@@ -23,16 +25,33 @@ function install(app: App, options: any = {}) {
|
||||
},
|
||||
/**
|
||||
* useCrud时会被执行
|
||||
* @param context,useCrud的参数
|
||||
* @param props,useCrud的参数
|
||||
*/
|
||||
commonOptions(context: UseCrudProps) {
|
||||
const crudBinding = context.expose?.crudBinding;
|
||||
commonOptions(props: UseCrudProps): CrudOptions {
|
||||
const crudBinding = props.crudExpose?.crudBinding;
|
||||
const opts: CrudOptions = {
|
||||
table: {
|
||||
size: "small",
|
||||
pagination: false,
|
||||
onResizeColumn: (w: any, col: any) => {
|
||||
crudBinding.value.table.columnsMap[col.key].width = w;
|
||||
onResizeColumn: (w: number, col: any) => {
|
||||
if (crudBinding.value?.table?.columnsMap && crudBinding.value?.table?.columnsMap[col.key]) {
|
||||
crudBinding.value.table.columnsMap[col.key].width = w;
|
||||
}
|
||||
},
|
||||
conditionalRender: {
|
||||
match(scope) {
|
||||
//不能用 !scope.value , 否则switch组件设置为关之后就消失了
|
||||
const { value, key } = scope;
|
||||
return !value && key != "_index" && value != false;
|
||||
},
|
||||
render() {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
},
|
||||
toolbar: {
|
||||
export: {
|
||||
fileType: "excel"
|
||||
}
|
||||
},
|
||||
rowHandle: {
|
||||
@@ -48,7 +67,7 @@ function install(app: App, options: any = {}) {
|
||||
}
|
||||
},
|
||||
request: {
|
||||
transformQuery: ({ page, form, sort }) => {
|
||||
transformQuery: ({ page, form, sort }: PageQuery): UserPageQuery => {
|
||||
const limit = page.pageSize;
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
const offset = limit * (currentPage - 1);
|
||||
@@ -64,7 +83,7 @@ function install(app: App, options: any = {}) {
|
||||
sort
|
||||
};
|
||||
},
|
||||
transformRes: ({ res }) => {
|
||||
transformRes: ({ res }: TransformResProps): PageRes => {
|
||||
const pageSize = res.limit;
|
||||
let currentPage = res.offset / pageSize;
|
||||
if (res.offset % pageSize === 0) {
|
||||
@@ -82,6 +101,13 @@ function install(app: App, options: any = {}) {
|
||||
width: "120px"
|
||||
}
|
||||
},
|
||||
async afterSubmit({ mode }) {
|
||||
if (mode === "add") {
|
||||
notification.success({ message: "添加成功" });
|
||||
} else if (mode === "edit") {
|
||||
notification.success({ message: "保存成功" });
|
||||
}
|
||||
},
|
||||
wrapperCol: {
|
||||
span: null
|
||||
}
|
||||
@@ -89,7 +115,8 @@ function install(app: App, options: any = {}) {
|
||||
};
|
||||
|
||||
// 从 useCrud({permission}) 里获取permission参数,去设置各个按钮的权限
|
||||
const crudPermission = useCrudPermission({ permission: context.permission });
|
||||
const permission = props.context?.permission || null;
|
||||
const crudPermission = useCrudPermission({ permission });
|
||||
return crudPermission.merge(opts);
|
||||
}
|
||||
});
|
||||
@@ -101,28 +128,28 @@ function install(app: App, options: any = {}) {
|
||||
// @ts-ignore
|
||||
defaultType: "cos",
|
||||
cos: {
|
||||
keepName: true,
|
||||
domain: "https://d2p-demo-1251260344.cos.ap-guangzhou.myqcloud.com",
|
||||
bucket: "d2p-demo-1251260344",
|
||||
region: "ap-guangzhou",
|
||||
secretId: "", //
|
||||
secretKey: "", // 传了secretKey 和secretId 代表使用本地签名模式(不安全,生产环境不推荐)
|
||||
getAuthorization(custom) {
|
||||
async getAuthorization(custom: any) {
|
||||
// 不传secretKey代表使用临时签名模式,此时此参数必传(安全,生产环境推荐)
|
||||
return request({
|
||||
const ret = request({
|
||||
url: "http://www.docmirror.cn:7070/api/upload/cos/getAuthorization",
|
||||
method: "get"
|
||||
}).then((ret: any) => {
|
||||
// 返回结构如下
|
||||
// ret.data:{
|
||||
// TmpSecretId,
|
||||
// TmpSecretKey,
|
||||
// XCosSecurityToken,
|
||||
// ExpiredTime, // SDK 在 ExpiredTime 时间前,不会再次调用 getAuthorization
|
||||
// }
|
||||
return ret;
|
||||
});
|
||||
// 返回结构要求如下
|
||||
// ret.data:{
|
||||
// TmpSecretId,
|
||||
// TmpSecretKey,
|
||||
// XCosSecurityToken,
|
||||
// ExpiredTime, // SDK 在 ExpiredTime 时间前,不会再次调用 getAuthorization
|
||||
// }
|
||||
return ret;
|
||||
},
|
||||
successHandle(ret) {
|
||||
successHandle(ret: any) {
|
||||
// 上传完成后可以在此处处理结果,修改url什么的
|
||||
console.log("success handle:", ret);
|
||||
return ret;
|
||||
@@ -134,6 +161,7 @@ function install(app: App, options: any = {}) {
|
||||
region: "oss-cn-shenzhen",
|
||||
accessKeyId: "",
|
||||
accessKeySecret: "",
|
||||
keepName: true,
|
||||
async getAuthorization(custom: any, context: any) {
|
||||
// 不传accessKeySecret代表使用临时签名模式,此时此参数必传(安全,生产环境推荐)
|
||||
const ret = await request({
|
||||
@@ -147,33 +175,62 @@ function install(app: App, options: any = {}) {
|
||||
// sdk配置
|
||||
secure: true // 默认为非https上传,为了安全,设置为true
|
||||
},
|
||||
successHandle(ret) {
|
||||
successHandle(ret: any) {
|
||||
// 上传完成后可以在此处处理结果,修改url什么的
|
||||
console.log("success handle:", ret);
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
qiniu: {
|
||||
keepName: true,
|
||||
bucket: "d2p-demo",
|
||||
async getToken(options) {
|
||||
async getToken(options: any) {
|
||||
const ret = await request({
|
||||
url: "http://www.docmirror.cn:7070/api/upload/qiniu/getToken",
|
||||
method: "get"
|
||||
});
|
||||
return ret; // {token:xxx,expires:xxx}
|
||||
},
|
||||
successHandle(ret) {
|
||||
successHandle(ret: any) {
|
||||
// 上传完成后可以在此处处理结果,修改url什么的
|
||||
console.log("success handle:", ret);
|
||||
return ret;
|
||||
},
|
||||
domain: "http://d2p.file.handsfree.work/"
|
||||
},
|
||||
s3: {
|
||||
keepName: true,
|
||||
//同时也支持minio
|
||||
bucket: "fast-crud",
|
||||
sdkOpts: {
|
||||
s3ForcePathStyle: true,
|
||||
signatureVersion: "v4",
|
||||
region: "us-east-1",
|
||||
forcePathStyle: true,
|
||||
//minio与s3完全适配
|
||||
endpoint: "https://play.min.io",
|
||||
credentials: {
|
||||
//不建议在客户端使用secretAccessKey来上传
|
||||
accessKeyId: "Q3AM3UQ867SPQQA43P2F", //访问登录名
|
||||
secretAccessKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" //访问密码
|
||||
}
|
||||
},
|
||||
//预签名配置,向后端获取上传的预签名连接
|
||||
async getSignedUrl(bucket: string, key: string, options: any, type: FsUploaderS3SignedUrlType) {
|
||||
return await GetSignedUrl(bucket, key, type);
|
||||
},
|
||||
successHandle(ret: any) {
|
||||
// 上传完成后可以在此处处理结果,修改url什么的
|
||||
console.log("success handle:", ret);
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
form: {
|
||||
keepName: true,
|
||||
action: "http://www.docmirror.cn:7070/api/upload/form/upload",
|
||||
name: "file",
|
||||
withCredentials: false,
|
||||
uploadRequest: async ({ action, file, onProgress }) => {
|
||||
uploadRequest: async ({ action, file, onProgress }: any) => {
|
||||
// @ts-ignore
|
||||
const data = new FormData();
|
||||
data.append("file", file);
|
||||
@@ -190,7 +247,7 @@ function install(app: App, options: any = {}) {
|
||||
}
|
||||
});
|
||||
},
|
||||
successHandle(ret) {
|
||||
successHandle(ret: any) {
|
||||
// 上传完成后的结果处理, 此处应返回格式为{url:xxx}
|
||||
return {
|
||||
url: "http://www.docmirror.cn:7070" + ret,
|
||||
@@ -203,14 +260,23 @@ function install(app: App, options: any = {}) {
|
||||
//安装editor
|
||||
app.use(FsExtendsEditor, {
|
||||
//编辑器的公共配置
|
||||
wangEditor: {}
|
||||
wangEditor: {
|
||||
editorConfig: {
|
||||
MENU_CONF: {}
|
||||
},
|
||||
toolbarConfig: {}
|
||||
}
|
||||
});
|
||||
app.use(FsExtendsJson);
|
||||
app.use(FsExtendsTime);
|
||||
app.use(FsExtendsCopyable);
|
||||
|
||||
const { addTypes, getType } = useTypes();
|
||||
//此处演示修改官方字段类型
|
||||
const textType = getType("text");
|
||||
textType.search.autoSearchTrigger = "change"; //修改官方的字段类型,设置为文本变化就触发查询
|
||||
|
||||
// 此处演示自定义字段类型
|
||||
const { addTypes } = useTypes();
|
||||
addTypes({
|
||||
time2: {
|
||||
//如果与官方字段类型同名,将会覆盖官方的字段类型
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
import "./iconify";
|
||||
import "./iconfont";
|
||||
import FastCrud from "./fast-crud/index";
|
||||
import FastCrud from "./fast-crud";
|
||||
import permission from "./permission";
|
||||
import { App } from "vue";
|
||||
function install(app: App, options: any = {}) {
|
||||
|
||||
+6
-4
@@ -1,9 +1,11 @@
|
||||
import permission from "./permission";
|
||||
import permission from "./permission.js";
|
||||
import permissionUtil from "../util.permission";
|
||||
const install = function (app) {
|
||||
const install = function (app: any) {
|
||||
app.directive("permission", permission);
|
||||
app.config.globalProperties.$hasPermissions = permissionUtil.hasPermissions;
|
||||
};
|
||||
|
||||
permission.install = install;
|
||||
export default permission;
|
||||
export default {
|
||||
install,
|
||||
...permission
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import permissionUtil from "../util.permission";
|
||||
export default {
|
||||
mounted(el, binding, vnode) {
|
||||
mounted(el: any, binding: any, vnode: any) {
|
||||
const { value } = binding;
|
||||
const hasPermission = permissionUtil.hasPermissions(value);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import permissionDirective from "./directive/index";
|
||||
import permissionDirective from "./directive/index.js";
|
||||
import { registerRouterHook } from "./hook";
|
||||
import util from "./util.permission";
|
||||
export * from "./use-crud-permission";
|
||||
@@ -11,7 +11,7 @@ export function usePermission() {
|
||||
}
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
install(app: any) {
|
||||
// 开启权限模块
|
||||
// 注册v-permission指令, 用于控制按钮权限
|
||||
app.use(permissionDirective);
|
||||
|
||||
@@ -21,7 +21,7 @@ interface PermissionState {
|
||||
* @param permissionList
|
||||
* @returns {*}
|
||||
*/
|
||||
function formatPermissions(menuTree: Array<any>, permissionList = []) {
|
||||
function formatPermissions(menuTree: Array<any>, permissionList: any[] = []) {
|
||||
if (menuTree == null) {
|
||||
menuTree = [];
|
||||
}
|
||||
@@ -44,17 +44,19 @@ export const usePermissionStore = defineStore({
|
||||
inited: false
|
||||
}),
|
||||
getters: {
|
||||
// @ts-ignore
|
||||
getPermissions() {
|
||||
// @ts-ignore
|
||||
return this.permissions;
|
||||
},
|
||||
// @ts-ignore
|
||||
isInited() {
|
||||
// @ts-ignore
|
||||
return this.inited;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
init({ permissions }) {
|
||||
init({ permissions }: any) {
|
||||
this.permissions = permissions;
|
||||
this.inited = true;
|
||||
},
|
||||
@@ -62,7 +64,7 @@ export const usePermissionStore = defineStore({
|
||||
this.permissions = [];
|
||||
this.inited = false;
|
||||
},
|
||||
resolve(resourceTree) {
|
||||
resolve(resourceTree: any) {
|
||||
const permissions = formatPermissions(resourceTree);
|
||||
this.init({ permissions });
|
||||
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
import { usePermission } from "/@/plugin/permission";
|
||||
import _ from "lodash-es";
|
||||
|
||||
export type UseCrudPermissionExtraProps = {
|
||||
hasActionPermission: (action: string) => boolean;
|
||||
};
|
||||
export type UseCrudPermissionExtra = (props: UseCrudPermissionExtraProps) => any;
|
||||
export type UseCrudPermissionCompProps = {
|
||||
prefix: string;
|
||||
extra?: UseCrudPermissionExtra;
|
||||
[key: string]: any;
|
||||
};
|
||||
export type UseCrudPermissionProps = {
|
||||
permission: string | UseCrudPermissionCompProps;
|
||||
};
|
||||
/**
|
||||
* 设置按钮动作权限
|
||||
* @param permission {prefix,extra}
|
||||
*/
|
||||
export function useCrudPermission({ permission }) {
|
||||
export function useCrudPermission({ permission }: UseCrudPermissionProps) {
|
||||
const { hasPermissions } = usePermission();
|
||||
|
||||
const prefix = permission instanceof Object ? permission.prefix : permission;
|
||||
|
||||
//根据权限显示按钮
|
||||
function hasActionPermission(action) {
|
||||
function hasActionPermission(action: string) {
|
||||
if (!prefix) {
|
||||
return true;
|
||||
}
|
||||
@@ -50,7 +62,7 @@ export function useCrudPermission({ permission }) {
|
||||
);
|
||||
}
|
||||
|
||||
function merge(userOptions) {
|
||||
function merge(userOptions: any) {
|
||||
const permissionOptions = buildCrudPermission();
|
||||
_.merge(permissionOptions, userOptions);
|
||||
return permissionOptions;
|
||||
|
||||
@@ -14,11 +14,11 @@ const util = {
|
||||
}
|
||||
const permissionStore = usePermissionStore();
|
||||
const userPermissionList = permissionStore.getPermissions;
|
||||
return userPermissionList.some((permission) => {
|
||||
return userPermissionList.some((permission: any) => {
|
||||
return need.includes(permission);
|
||||
});
|
||||
},
|
||||
requirePermissions: (value) => {
|
||||
requirePermissions: (value: any) => {
|
||||
if (!util.hasPermissions(value)) {
|
||||
message.error("对不起,您没有权限执行此操作");
|
||||
throw new NoPermissionError();
|
||||
|
||||
Reference in New Issue
Block a user