diff --git a/docker_env/nginx/my.conf b/docker_env/nginx/my.conf index 94fe805e744b5b5455a56f14710d64a525bf5627..30fa2108d1ae318b5841bfb237d389444a241ad1 100644 --- a/docker_env/nginx/my.conf +++ b/docker_env/nginx/my.conf @@ -28,6 +28,6 @@ server { proxy_send_timeout 600s; real_ip_header X-Forwarded-For; rewrite ^/api/(.*)$ /$1 break; #重写 - proxy_pass http://178.10.0.12:8000/; # 设置代理服务器的协议和地址 + proxy_pass http://177.8.0.12:8000/; # 设置代理服务器的协议和地址 } } diff --git a/web/.env.production b/web/.env.production index 70cd18d579ea1b477f8fd6956eed1b8dcaaf5dab..998aa5e15fe3f7cd5a3765c4c1b82dd2a629b2f0 100644 --- a/web/.env.production +++ b/web/.env.production @@ -2,7 +2,7 @@ ENV = 'production' # 线上环境接口地址 -VITE_API_URL = '' +VITE_API_URL = '/api' # docker-compose部署不需要修改,nginx容器自动代理了这个地址 # 是否启用按钮权限 VITE_PM_ENABLED = true diff --git a/web/package.json b/web/package.json index 4349cde8648a36bbca061ff9b058bce7c0b54ef4..345af77ca283cd8d7dd8cc813c37868988b1809a 100644 --- a/web/package.json +++ b/web/package.json @@ -10,10 +10,10 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.0.10", - "@fast-crud/fast-crud": "^1.11.10", - "@fast-crud/fast-extends": "^1.11.10", - "@fast-crud/ui-element": "^1.11.10", - "@fast-crud/ui-interface": "^1.11.9", + "@fast-crud/fast-crud": "^1.13.2", + "@fast-crud/fast-extends": "^1.13.2", + "@fast-crud/ui-element": "^1.13.2", + "@fast-crud/ui-interface": "^1.13.2", "@vitejs/plugin-vue-jsx": "^3.0.0", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.12", diff --git a/web/src/settings.ts b/web/src/settings.ts index 588a6a058d1eb260556e63c1b6de2620278da85d..b43526eb571a2474527e161d52751449aa98e9e5 100644 --- a/web/src/settings.ts +++ b/web/src/settings.ts @@ -7,8 +7,9 @@ import { setLogger } from '@fast-crud/fast-crud'; import ui from '@fast-crud/ui-element'; import { request } from '/@/utils/service'; //扩展包 -import { FsExtendsEditor } from '@fast-crud/fast-extends'; +import { FsExtendsEditor,FsExtendsUploader } from '@fast-crud/fast-extends'; import '@fast-crud/fast-extends/dist/style.css'; +import { successMessage, successNotification } from '/@/utils/message'; export default { async install(app: any, options: any) { // 先安装ui @@ -18,7 +19,10 @@ export default { //i18n, //i18n配置,可选,默认使用中文,具体用法请看demo里的 src/i18n/index.js 文件 // 此处配置公共的dictRequest(字典请求) async dictRequest({ dict }: any) { - return await request({ url: dict.url, params: dict.params || {} }); //根据dict的url,异步返回一个字典数组 + //根据dict的url,异步返回一个字典数组 + return await request({ url: dict.url, params: dict.params || {} }).then((res:any)=>{ + return res.data + }); }, //公共crud配置 commonOptions() { @@ -40,6 +44,14 @@ export default { return { records: res.data, currentPage: res.page, pageSize: res.limit, total: res.total }; }, }, + form: { + afterSubmit(ctx: any) { + // 增加crud提示 + if (ctx.res.code == 2000) { + successNotification(ctx.res.msg); + } + }, + }, /* search: { layout: 'multi-line', collapse: true, @@ -63,6 +75,39 @@ export default { width: 300, }, }); + // 文件上传 + app.use(FsExtendsUploader, { + defaultType: "form", + form: { + action: `/api/system/file/`, + name: "file", + withCredentials: false, + uploadRequest: async ({ action, file, onProgress }) => { + // @ts-ignore + const data = new FormData(); + data.append("file", file); + return await request({ + url: action, + method: "post", + timeout: 60000, + headers: { + "Content-Type": "multipart/form-data" + }, + data, + onUploadProgress: (p) => { + onProgress({ percent: Math.round((p.loaded / p.total) * 100) }); + } + }); + }, + successHandle(ret) { + // 上传完成后的结果处理, 此处应返回格式为{url:xxx,key:xxx} + return { + url: getBaseURL() + ret.data.url, + key: ret.data.id + }; + } + } + }) setLogger({ level: 'error' }); // 设置自动染色 const dictComponentList = ['dict-cascader', 'dict-checkbox', 'dict-radio', 'dict-select', 'dict-switch', 'dict-tree']; diff --git a/web/src/utils/baseUrl.ts b/web/src/utils/baseUrl.ts index 617e9f9ec2965477ca3fdaee8c0b03cbc6556f31..c22daa83ff86972834bad25c1d701ebb6f56787b 100644 --- a/web/src/utils/baseUrl.ts +++ b/web/src/utils/baseUrl.ts @@ -1,61 +1,67 @@ +import { pluginsAll } from '/@/views/plugins/index'; + /** * @description 校验是否为租户模式。租户模式把域名替换成 域名 加端口 */ export const getBaseURL = function () { - var baseURL = import.meta.env.VITE_API_URL as any - var param = baseURL.split('/')[3] || '' - if (window.pluginsAll && window.pluginsAll.indexOf('dvadmin-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) { - // 1.把127.0.0.1 替换成和前端一样域名 - // 2.把 ip 地址替换成和前端一样域名 - // 3.把 /api 或其他类似的替换成和前端一样域名 - // document.domain - var host = baseURL.split('/')[2] - if (host) { - var prot = baseURL.split(':')[2] || 80 - if (prot === 80 || prot === 443) { - host = document.domain - } else { - host = document.domain + ':' + prot - } - baseURL = baseURL.split('/')[0] + '//' + baseURL.split('/')[1] + host + '/' + param - } else { - baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL - } - } - if (!baseURL.endsWith('/')) { - baseURL += '/' - } - return baseURL -} + var baseURL = import.meta.env.VITE_API_URL as any; + var param = baseURL.split('/')[3] || ''; + // @ts-ignore + if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) { + // 1.把127.0.0.1 替换成和前端一样域名 + // 2.把 ip 地址替换成和前端一样域名 + // 3.把 /api 或其他类似的替换成和前端一样域名 + // document.domain + + var host = baseURL.split('/')[2]; + if (host) { + var port = baseURL.split(':')[2] || 80; + if (port === 80 || port === 443) { + host = document.domain; + } else { + host = document.domain + ':' + port; + } + baseURL = baseURL.split('/')[0] + '//' + baseURL.split('/')[1] + host + '/' + param; + } else { + baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL; + } + } + if (!baseURL.endsWith('/')) { + baseURL += '/'; + } + return baseURL; +}; export const getWsBaseURL = function () { - let baseURL = import.meta.env.VITE_API_URL as any - let param = baseURL.split('/')[3] || '' - if (window.pluginsAll && window.pluginsAll.indexOf('dvadmin-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) { - // 1.把127.0.0.1 替换成和前端一样域名 - // 2.把 ip 地址替换成和前端一样域名 - // 3.把 /api 或其他类似的替换成和前端一样域名 - // document.domain - var host = baseURL.split('/')[2] - if (host) { - var prot = baseURL.split(':')[2] || 80 - if (prot === 80 || prot === 443) { - host = document.domain - } else { - host = document.domain + ':' + prot - } - baseURL = baseURL.split('/')[0] + '//' + baseURL.split('/')[1] + host + '/' + param - } else { - baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL - } - } else if (param !== '' || baseURL.startsWith('/')) { - baseURL = (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.hostname + (location.port ? ':' : '') + location.port + baseURL - } - if (!baseURL.endsWith('/')) { - baseURL += '/' - } - if (baseURL.startsWith('http')) { // https 也默认会被替换成 wss - baseURL = baseURL.replace('http', 'ws') - } - return baseURL -} + let baseURL = import.meta.env.VITE_API_URL as any; + let param = baseURL.split('/')[3] || ''; + // @ts-ignore + if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) { + // 1.把127.0.0.1 替换成和前端一样域名 + // 2.把 ip 地址替换成和前端一样域名 + // 3.把 /api 或其他类似的替换成和前端一样域名 + // document.domain + var host = baseURL.split('/')[2]; + if (host) { + var port = baseURL.split(':')[2] || 80; + if (port === 80 || port === 443) { + host = document.domain; + } else { + host = document.domain + ':' + port; + } + baseURL = baseURL.split('/')[0] + '//' + baseURL.split('/')[1] + host + '/' + param; + } else { + baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL; + } + } else if (param !== '' || baseURL.startsWith('/')) { + baseURL = (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.hostname + (location.port ? ':' : '') + location.port + baseURL; + } + if (!baseURL.endsWith('/')) { + baseURL += '/'; + } + if (baseURL.startsWith('http')) { + // https 也默认会被替换成 wss + baseURL = baseURL.replace('http', 'ws'); + } + return baseURL; +}; diff --git a/web/src/utils/message.ts b/web/src/utils/message.ts index 0e3bc4b133884b7c48e025c8d4fa896946e65538..a022c0ba5b4ff7c06f0804e3632fce85871c0497 100644 --- a/web/src/utils/message.ts +++ b/web/src/utils/message.ts @@ -1,10 +1,10 @@ -import { ElMessage, MessageOptions } from 'element-plus'; +import { ElMessage, ElNotification, MessageOptions } from 'element-plus'; export function message(message: string, option?: MessageOptions) { ElMessage({ message, ...option }); } export function successMessage(message: string, option?: MessageOptions) { - ElMessage({ message, ...option, type: 'success' }); + ElMessage({ message, type: 'success' }); } export function warningMessage(message: string, option?: MessageOptions) { ElMessage({ message, ...option, type: 'warning' }); @@ -15,3 +15,19 @@ export function errorMessage(message: string, option?: MessageOptions) { export function infoMessage(message: string, option?: MessageOptions) { ElMessage({ message, ...option, type: 'info' }); } + +export function notification(message: string) { + ElNotification({ message }); +} +export function successNotification(message: string) { + ElNotification({ message, type: 'success' }); +} +export function warningNotification(message: string) { + ElNotification({ message, type: 'warning' }); +} +export function errorNotification(message: string) { + ElNotification({ message, type: 'error' }); +} +export function infoNotification(message: string) { + ElNotification({ message, type: 'info' }); +} diff --git a/web/src/utils/service.ts b/web/src/utils/service.ts index c3b46446fcfbe4f02ab0b09219eba8c3a22b9cfb..023f268a2eccb54c2d202d7cdf144439080befca 100644 --- a/web/src/utils/service.ts +++ b/web/src/utils/service.ts @@ -1,7 +1,7 @@ import axios from 'axios'; import { get } from 'lodash-es'; -import { ElMessage, ElMessageBox } from 'element-plus' -import type { Action } from 'element-plus' +import { ElMessage, ElMessageBox } from 'element-plus'; +import type { Action } from 'element-plus'; // @ts-ignore import { errorLog, errorCreate } from './tools.ts'; @@ -9,6 +9,7 @@ import { errorLog, errorCreate } from './tools.ts'; // import { useUserStore } from "../store/modules/user"; import { Local, Session } from '/@/utils/storage'; import qs from 'qs'; +import { getBaseURL } from './baseUrl'; /** * @description 创建请求实例 */ @@ -17,16 +18,19 @@ function createService() { const service = axios.create({ timeout: 20000, headers: { - 'Content-Type': 'application/json;charset=utf-8' + 'Content-Type': 'application/json;charset=utf-8', }, paramsSerializer: { serialize(params) { - return qs.stringify(params, { indices: false,encoder: (val:string) => { + return qs.stringify(params, { + indices: false, + encoder: (val: string) => { if (typeof val === 'boolean') { return val ? 1 : 0; } return val; - } }); + }, + }); }, }, }); @@ -76,7 +80,7 @@ function createService() { callback: (action: Action) => { window.location.reload(); }, - }) + }); errorCreate(`${dataAxios.msg}: ${response.config.url}`); break; case 2000: @@ -108,7 +112,7 @@ function createService() { callback: (action: Action) => { window.location.reload(); }, - }) + }); break; case 403: error.message = '拒绝访问'; @@ -162,7 +166,7 @@ function createRequestFunction(service: any) { 'Content-Type': get(config, 'headers.Content-Type', 'application/json'), }, timeout: 5000, - baseURL: import.meta.env.VITE_API_URL as any, + baseURL: getBaseURL(), data: {}, }; diff --git a/web/src/views/plugins/index.ts b/web/src/views/plugins/index.ts index fe9b889c5ee795855ba37a5f64f479a48e3607eb..7ba8bf9e3e32686bc51b1c9f80357432fa80ab22 100644 --- a/web/src/views/plugins/index.ts +++ b/web/src/views/plugins/index.ts @@ -1,5 +1,5 @@ import { defineAsyncComponent, AsyncComponentLoader } from 'vue'; - +export let pluginsAll: any = []; // 扫描插件目录并注册插件 export const scanAndInstallPlugins = (app: any) => { const components = import.meta.glob('./**/*.vue'); @@ -11,5 +11,6 @@ export const scanAndInstallPlugins = (app: any) => { const pluginsName = key.match(/\/([^\/]*)\//)?.[1]; pluginNames.add(pluginsName); } - console.log('已发现插件:', Array.from(pluginNames)); + pluginsAll = Array.from(pluginNames); + console.log('已发现插件:', pluginsAll); }; diff --git a/web/src/views/system/config/components/addContent.vue b/web/src/views/system/config/components/addContent.vue index 6284a181f176c0551fdf904ef96f3ab9ef504340..e7e9e4d0545fe35bc85ffed9023dc959b5791bdc 100644 --- a/web/src/views/system/config/components/addContent.vue +++ b/web/src/views/system/config/components/addContent.vue @@ -40,7 +40,7 @@ - 立即创建 + 立即创建 @@ -49,7 +49,7 @@