mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-17 17:26:38 +08:00
refactor(projects): 代码优化
ISSUES CLOSED: \
This commit is contained in:
parent
8f6d6ce3cb
commit
d28b9039bb
@ -1,13 +1,13 @@
|
||||
import { computed } from 'vue';
|
||||
import { useAppStore, useThemeStore } from '@/store';
|
||||
|
||||
type LayoutMode = 'vertical' | 'horizontal';
|
||||
type LayoutHeaderProps = Record<EnumType.ThemeLayoutMode, GlobalHeaderProps>;
|
||||
|
||||
export function useBasicLayout() {
|
||||
const app = useAppStore();
|
||||
const theme = useThemeStore();
|
||||
|
||||
type LayoutMode = 'vertical' | 'horizontal';
|
||||
const mode = computed(() => {
|
||||
const vertical: LayoutMode = 'vertical';
|
||||
const horizontal: LayoutMode = 'horizontal';
|
||||
|
@ -3,7 +3,6 @@ export enum EnumUserRole {
|
||||
super = '超级管理员',
|
||||
admin = '管理员',
|
||||
user = '普通用户'
|
||||
// custom = '自定义角色'
|
||||
}
|
||||
|
||||
/** 登录模块 */
|
||||
|
@ -31,5 +31,6 @@ export enum EnumDataType {
|
||||
date = '[object Date]',
|
||||
regexp = '[object RegExp]',
|
||||
set = '[object Set]',
|
||||
map = '[object Map]'
|
||||
map = '[object Map]',
|
||||
file = '[object File]'
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
|
||||
|
||||
ctx.fillStyle = randomColor(180, 230);
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)];
|
||||
imgCode += text;
|
||||
@ -81,5 +82,6 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
|
||||
ctx.fillStyle = randomColor(150, 200);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
return imgCode;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import useCountDown from './useCountDown';
|
||||
export default function useSmsCode() {
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
const { counts, start, isCounting } = useCountDown(60);
|
||||
|
||||
const initLabel = '获取验证码';
|
||||
const countingLabel = (second: number) => `${second}秒后重新获取`;
|
||||
const label = computed(() => {
|
||||
@ -40,6 +41,7 @@ export default function useSmsCode() {
|
||||
async function getSmsCode(phone: string) {
|
||||
const valid = isPhoneValid(phone);
|
||||
if (!valid || loading.value) return;
|
||||
|
||||
startLoading();
|
||||
const { data } = await fetchSmsCode(phone);
|
||||
if (data) {
|
||||
|
@ -13,9 +13,12 @@ export default function useReload() {
|
||||
async function handleReload(duration = 0) {
|
||||
setFalse();
|
||||
await nextTick();
|
||||
setTimeout(() => {
|
||||
setTrue();
|
||||
}, duration);
|
||||
|
||||
if (duration > 0) {
|
||||
setTimeout(() => {
|
||||
setTrue();
|
||||
}, duration);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -33,3 +33,6 @@ export function isSet(data: unknown) {
|
||||
export function isMap(data: unknown) {
|
||||
return Object.prototype.toString.call(data) === EnumDataType.map;
|
||||
}
|
||||
export function isFile(data: unknown) {
|
||||
return Object.prototype.toString.call(data) === EnumDataType.file;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import qs from 'qs';
|
||||
import FormData from 'form-data';
|
||||
import { EnumContentType } from '@/enum';
|
||||
import { isArray } from '../common';
|
||||
import { isArray, isFile } from '../common';
|
||||
|
||||
/**
|
||||
* 请求数据的转换
|
||||
@ -17,20 +17,35 @@ export async function transformRequestData(requestData: any, contentType?: strin
|
||||
}
|
||||
// form-data类型转换
|
||||
if (contentType === EnumContentType.formData) {
|
||||
const key = Object.keys(requestData)[0];
|
||||
const file = requestData.data[key];
|
||||
data = await transformFile(file, key);
|
||||
data = await handleFormData(requestData);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async function handleFormData(data: Record<string, any>) {
|
||||
const formData = new FormData();
|
||||
const entries = Object.entries(data);
|
||||
|
||||
entries.forEach(async ([key, value]) => {
|
||||
const isFileType = isFile(value) || (isArray(value) && value.length && isFile(value[0]));
|
||||
|
||||
if (isFileType) {
|
||||
await transformFile(formData, key, value);
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口为上传文件的类型时数据转换
|
||||
* @param file - 单文件或多文件
|
||||
* @param key - 文件的属性名
|
||||
* @param file - 单文件或多文件
|
||||
*/
|
||||
async function transformFile(file: File[] | File, key: string) {
|
||||
const formData = new FormData();
|
||||
async function transformFile(formData: FormData, key: string, file: File[] | File) {
|
||||
if (isArray(file)) {
|
||||
// 多文件
|
||||
await Promise.all(
|
||||
@ -43,5 +58,4 @@ async function transformFile(file: File[] | File, key: string) {
|
||||
// 单文件
|
||||
await formData.append(key, file);
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="403" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../../system-view/components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="404" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../../system-view/components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="500" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../../system-view/components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -1,3 +0,0 @@
|
||||
import ExceptionBase from './ExceptionBase.vue';
|
||||
|
||||
export { ExceptionBase };
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="403" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="404" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="404" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -2,8 +2,6 @@
|
||||
<exception-base type="500" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ExceptionBase } from '../components';
|
||||
</script>
|
||||
<script lang="ts" setup></script>
|
||||
|
||||
<style scoped></style>
|
||||
|
Loading…
Reference in New Issue
Block a user