mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: 代码小优化
This commit is contained in:
@@ -74,8 +74,8 @@ function build() {
|
|||||||
# fi
|
# fi
|
||||||
|
|
||||||
if [ "${copyDocScript}" == "1" ] ; then
|
if [ "${copyDocScript}" == "1" ] ; then
|
||||||
echo_green "拷贝脚本等资源文件[config.yml、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
|
echo_green "拷贝脚本等资源文件[config.yml.example、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
|
||||||
cp ${server_folder}/config.yml ${toFolder}
|
cp ${server_folder}/config.yml.example ${toFolder}
|
||||||
cp ${server_folder}/mayfly-go.sql ${toFolder}
|
cp ${server_folder}/mayfly-go.sql ${toFolder}
|
||||||
cp ${server_folder}/readme.txt ${toFolder}
|
cp ${server_folder}/readme.txt ${toFolder}
|
||||||
cp ${server_folder}/startup.sh ${toFolder}
|
cp ${server_folder}/startup.sh ${toFolder}
|
||||||
|
|||||||
@@ -12,14 +12,14 @@
|
|||||||
"@element-plus/icons-vue": "^2.1.0",
|
"@element-plus/icons-vue": "^2.1.0",
|
||||||
"asciinema-player": "^3.5.0",
|
"asciinema-player": "^3.5.0",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"countup.js": "^2.0.7",
|
"countup.js": "^2.7.0",
|
||||||
"cropperjs": "^1.5.11",
|
"cropperjs": "^1.5.11",
|
||||||
"echarts": "^5.4.0",
|
"echarts": "^5.4.0",
|
||||||
"element-plus": "^2.3.8",
|
"element-plus": "^2.3.8",
|
||||||
"jsencrypt": "^3.3.1",
|
"jsencrypt": "^3.3.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mitt": "^3.0.1",
|
"mitt": "^3.0.1",
|
||||||
"monaco-editor": "^0.40.0",
|
"monaco-editor": "^0.41.0",
|
||||||
"monaco-sql-languages": "^0.11.0",
|
"monaco-sql-languages": "^0.11.0",
|
||||||
"monaco-themes": "^0.4.4",
|
"monaco-themes": "^0.4.4",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"sass": "^1.62.0",
|
"sass": "^1.62.0",
|
||||||
"sass-loader": "^13.2.0",
|
"sass-loader": "^13.2.0",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.0.2",
|
||||||
"vite": "^4.4.7",
|
"vite": "^4.4.9",
|
||||||
"vue-eslint-parser": "^9.1.1"
|
"vue-eslint-parser": "^9.1.1"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import router from '../router';
|
import router from '../router';
|
||||||
import Axios from 'axios';
|
import Axios from 'axios';
|
||||||
import { ResultEnum } from './enums';
|
|
||||||
import config from './config';
|
import config from './config';
|
||||||
import { getSession } from './utils/storage';
|
import { getSession } from './utils/storage';
|
||||||
import { templateResolve } from './utils/string';
|
import { templateResolve } from './utils/string';
|
||||||
@@ -21,6 +20,14 @@ export interface Result {
|
|||||||
data?: any;
|
data?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ResultEnum {
|
||||||
|
SUCCESS = 200,
|
||||||
|
ERROR = 400,
|
||||||
|
PARAM_ERROR = 405,
|
||||||
|
SERVER_ERROR = 500,
|
||||||
|
NO_PERMISSION = 501,
|
||||||
|
}
|
||||||
|
|
||||||
const baseUrl: string = config.baseApiUrl;
|
const baseUrl: string = config.baseApiUrl;
|
||||||
const baseWsUrl: string = config.baseWsUrl;
|
const baseWsUrl: string = config.baseWsUrl;
|
||||||
|
|
||||||
@@ -60,34 +67,46 @@ service.interceptors.response.use(
|
|||||||
(response) => {
|
(response) => {
|
||||||
// 获取请求返回结果
|
// 获取请求返回结果
|
||||||
const data: Result = response.data;
|
const data: Result = response.data;
|
||||||
|
if (data.code === ResultEnum.SUCCESS) {
|
||||||
|
return data.data;
|
||||||
|
}
|
||||||
// 如果提示没有权限,则移除token,使其重新登录
|
// 如果提示没有权限,则移除token,使其重新登录
|
||||||
if (data.code === ResultEnum.NO_PERMISSION) {
|
if (data.code === ResultEnum.NO_PERMISSION) {
|
||||||
router.push({
|
router.push({
|
||||||
path: '/401',
|
path: '/401',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (data.code === ResultEnum.SUCCESS) {
|
|
||||||
return data.data;
|
|
||||||
} else {
|
|
||||||
return Promise.reject(data);
|
return Promise.reject(data);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(e: any) => {
|
(e: any) => {
|
||||||
|
const rejectPromise = Promise.reject(e);
|
||||||
|
|
||||||
|
const statusCode = e.response?.status;
|
||||||
|
if (statusCode == 500) {
|
||||||
|
notifyErrorMsg('服务器未知异常');
|
||||||
|
return rejectPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusCode == 404) {
|
||||||
|
notifyErrorMsg('请求接口未找到');
|
||||||
|
return rejectPromise;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.message) {
|
if (e.message) {
|
||||||
// 对响应错误做点什么
|
// 对响应错误做点什么
|
||||||
if (e.message.indexOf('timeout') != -1) {
|
if (e.message.indexOf('timeout') != -1) {
|
||||||
notifyErrorMsg('网络超时');
|
notifyErrorMsg('网络请求超时');
|
||||||
} else if (e.message == 'Network Error') {
|
return rejectPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.message == 'Network Error') {
|
||||||
notifyErrorMsg('网络连接错误');
|
notifyErrorMsg('网络连接错误');
|
||||||
} else if (e.message.indexOf('404')) {
|
return rejectPromise;
|
||||||
notifyErrorMsg('请求接口找不到');
|
|
||||||
} else {
|
|
||||||
if (e.response.data) ElMessage.error(e.response.statusText);
|
|
||||||
else notifyErrorMsg('接口路径找不到');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(e);
|
notifyErrorMsg('网络请求错误');
|
||||||
|
return rejectPromise;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,15 @@ const props = defineProps({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
type: Object,
|
type: [Object, String, Number],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultType = 'primary';
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
type: 'primary',
|
type: defaultType,
|
||||||
color: '',
|
color: '',
|
||||||
enumLabel: '',
|
enumLabel: '',
|
||||||
});
|
});
|
||||||
@@ -50,6 +52,8 @@ const convert = (value: any) => {
|
|||||||
if (enumValue.tag) {
|
if (enumValue.tag) {
|
||||||
state.color = enumValue.tag.color;
|
state.color = enumValue.tag.color;
|
||||||
state.type = enumValue.tag.type;
|
state.type = enumValue.tag.type;
|
||||||
|
} else {
|
||||||
|
state.type = defaultType;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -314,8 +314,16 @@ onMounted(() => {
|
|||||||
} else {
|
} else {
|
||||||
state.inputWidth = props.inputWidth;
|
state.inputWidth = props.inputWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', () => {
|
||||||
|
calcuTableHeight();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const calcuTableHeight = () => {
|
||||||
|
state.tableMaxHeight = window.innerHeight - 240 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
const formatText = (data: any)=> {
|
const formatText = (data: any)=> {
|
||||||
state.formatVal = '';
|
state.formatVal = '';
|
||||||
try {
|
try {
|
||||||
@@ -362,7 +370,7 @@ const reset = () => {
|
|||||||
for (let qi of props.query) {
|
for (let qi of props.query) {
|
||||||
state.queryForm[qi.prop] = null;
|
state.queryForm[qi.prop] = null;
|
||||||
}
|
}
|
||||||
console.log(state.queryForm);
|
|
||||||
changePageNum(1);
|
changePageNum(1);
|
||||||
emit('update:queryForm', state.queryForm);
|
emit('update:queryForm', state.queryForm);
|
||||||
execQuery();
|
execQuery();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { useKeepALiveNames } from '@/store/keepAliveNames';
|
|||||||
* @method import.meta.glob
|
* @method import.meta.glob
|
||||||
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
||||||
*/
|
*/
|
||||||
const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}');
|
const viewsModules: any = import.meta.glob(['../views/**/*.{vue,tsx}', '!../views/layout/**/*.{vue,tsx}']);
|
||||||
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...viewsModules });
|
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...viewsModules });
|
||||||
|
|
||||||
// 添加静态路由
|
// 添加静态路由
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="cron" label="cron表达式">
|
<el-form-item prop="cron" label="cron表达式">
|
||||||
<el-input v-model="form.cron" placeholder="请输入cron表达式"></el-input>
|
<el-input v-model="form.cron" placeholder="只支持5位表达式,不支持秒级.如 0/2 * * * * 表示每两分钟执行"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="status" label="状态">
|
<el-form-item prop="status" label="状态">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, reactive, watch, toRefs, onMounted } from 'vue';
|
import { ref, reactive, toRefs, onMounted } from 'vue';
|
||||||
import { redisApi } from './api';
|
import { redisApi } from './api';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { notEmpty } from '@/common/assert';
|
import { notEmpty } from '@/common/assert';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<span style="font-size: 14px"> <SvgIcon name="info-filled" />红色、橙色字体表示禁用状态 </span>
|
<span style="font-size: 14px"> <SvgIcon name="info-filled" />红色、橙色字体表示禁用状态 </span>
|
||||||
</div>
|
</div>
|
||||||
<el-button v-auth="'resource:add'" type="primary" icon="plus" @click="addResource(false)">添加</el-button>
|
<el-button v-auth="perms.addResource" type="primary" icon="plus" @click="addResource(false)">添加</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-tree
|
<el-tree
|
||||||
class="none-select"
|
class="none-select"
|
||||||
@@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="view" type="info" :underline="false" />
|
<el-link @click.prevent="info(data)" style="margin-left: 25px" icon="view" type="info" :underline="false" />
|
||||||
|
|
||||||
<el-link v-auth="'resource:update'" @click.prevent="editResource(data)" class="ml5" type="primary" icon="edit" :underline="false" />
|
<el-link v-auth="perms.updateResource" @click.prevent="editResource(data)" class="ml5" type="primary" icon="edit" :underline="false" />
|
||||||
|
|
||||||
<el-link
|
<el-link
|
||||||
v-auth="'resource:add'"
|
v-auth="perms.addResource"
|
||||||
@click.prevent="addResource(data)"
|
@click.prevent="addResource(data)"
|
||||||
v-if="data.type === menuTypeValue"
|
v-if="data.type === menuTypeValue"
|
||||||
icon="circle-plus"
|
icon="circle-plus"
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<el-link
|
<el-link
|
||||||
v-auth="'resource:changeStatus'"
|
v-auth="perms.changeStatus"
|
||||||
@click.prevent="changeStatus(data, -1)"
|
@click.prevent="changeStatus(data, -1)"
|
||||||
v-if="data.status === 1"
|
v-if="data.status === 1"
|
||||||
icon="circle-close"
|
icon="circle-close"
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<el-link
|
<el-link
|
||||||
v-auth="'resource:changeStatus'"
|
v-auth="perms.changeStatus"
|
||||||
@click.prevent="changeStatus(data, 1)"
|
@click.prevent="changeStatus(data, 1)"
|
||||||
v-if="data.status === -1"
|
v-if="data.status === -1"
|
||||||
type="success"
|
type="success"
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
class="ml5"
|
class="ml5"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<el-link v-auth="'resource:delete'" @click.prevent="deleteMenu(data)" type="danger" icon="delete" :underline="false" plain class="ml5" />
|
<el-link v-auth="perms.delResource" @click.prevent="deleteMenu(data)" type="danger" icon="delete" :underline="false" plain class="ml5" />
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-tree>
|
</el-tree>
|
||||||
@@ -138,6 +138,13 @@ import EnumValue from '@/common/Enum';
|
|||||||
const menuTypeValue = ResourceTypeEnum.Menu.value;
|
const menuTypeValue = ResourceTypeEnum.Menu.value;
|
||||||
const permissionTypeValue = ResourceTypeEnum.Permission.value;
|
const permissionTypeValue = ResourceTypeEnum.Permission.value;
|
||||||
|
|
||||||
|
const perms = {
|
||||||
|
addResource: 'resource:add',
|
||||||
|
delResource: 'resource:delete',
|
||||||
|
updateResource: 'resource:update',
|
||||||
|
changeStatus: 'resource:changeStatus',
|
||||||
|
};
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
label: 'name',
|
label: 'name',
|
||||||
children: 'children',
|
children: 'children',
|
||||||
|
|||||||
Reference in New Issue
Block a user