Skip to content

Commit

Permalink
refactor(api): project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Nov 9, 2023
1 parent ad14520 commit 830246d
Show file tree
Hide file tree
Showing 155 changed files with 1,317 additions and 1,729 deletions.
3 changes: 3 additions & 0 deletions apps/admin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
root: true,
extends: ['@vben'],
rules: {
'no-undef': 'off',
},
};
29 changes: 0 additions & 29 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,6 @@
"test:gzip": "npx http-server dist --cors --gzip -c-1",
"type:check": "vue-tsc --noEmit --skipLibCheck"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write",
"eslint --fix"
],
"{!(package)*.json,*.code-snippets,.!(browserslist)*rc}": [
"prettier --write--parser json"
],
"package.json": [
"prettier --write"
],
"*.vue": [
"prettier --write",
"eslint --fix",
"stylelint --fix"
],
"*.{scss,less,styl,html}": [
"prettier --write",
"stylelint --fix"
],
"*.md": [
"prettier --write"
]
},
"config": {
"commitizen": {
"path": "node_modules/cz-git"
}
},
"dependencies": {
"@ant-design/icons-vue": "^7.0.1",
"@iconify/iconify": "^3.1.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/admin/src/components/Upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { withInstall } from '/@/utils';
import basicUpload from './src/BasicUpload.vue';
import uploadImage from './src/components/ImageUpload.vue';
import avatarUpload from './src/AvatarUpload.vue';

export const ImageUpload = withInstall(uploadImage);
export const BasicUpload = withInstall(basicUpload);
export const AvatarUpload = withInstall(avatarUpload);
119 changes: 119 additions & 0 deletions apps/admin/src/components/Upload/src/AvatarUpload.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<template>
<div>
<Upload
v-model:file-list="fileList"
name="file"
list-type="picture-card"
class="avatar-uploader"
:action="uploadUrl"
:before-upload="beforeUpload"
:headers="requestHeaders"
@preview="handlePreview"
@change="handleChange"
>
<img v-if="previewImage" :src="previewImage" alt="logo" />
<div v-if="fileList.length < 1">
<loading-outlined v-if="loading" />
<plus-outlined v-else />
<div class="ant-upload-text">上传</div>
</div>
</Upload>
<Modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%" :src="previewImage" />
</Modal>

<Modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%" :src="previewImage" />
</Modal>
</div>
</template>
<script lang="ts" setup>
import { Upload, Modal } from 'ant-design-vue';
import { PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { uploadUrl } from '/@/api/sys/upload';
import { getToken } from '/@/utils/auth';
import { ref, watch } from 'vue';
interface FileItem {
uid?: string;
name?: string;
status?: string;
response?: string;
percent?: number;
url?: string;
preview?: string;
originFileObj?: any;
}
function getBase64(file: File) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
const props = defineProps({
avatar: {
type: String,
},
});
const fileList = ref<FileItem[]>([]);
const emit = defineEmits(['change']);
const { createMessage } = useMessage();
const requestHeaders = {
authorization: 'Bearer ' + getToken(),
};
const loading = ref<boolean>(false);
const previewVisible = ref<boolean>(false);
const previewImage = ref<string | undefined>('');
const handleCancel = () => {
previewImage.value = '';
previewVisible.value = false;
};
const handlePreview = async (file) => {
if (!file.url && !file.preview) {
file.preview = (await getBase64(file.originFileObj)) as string;
}
previewImage.value = file.url || file.preview;
previewVisible.value = true;
};
const handleChange = ({ fileList: newFileList }) => {
let temp = newFileList[0];
if (temp?.response) {
temp.url = temp.response;
}
emit('change', temp);
};
const beforeUpload = (file) => {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isJpgOrPng) {
createMessage.error('请选择正确的图片格式');
}
const isLt2M = file.size / 1024 / 1024 < 1;
if (!isLt2M) {
createMessage.error('图片大小请小于1M');
}
return isJpgOrPng && isLt2M;
};
watch(
() => props.avatar,
(val) => {
fileList.value = val ? [{ url: val }] : [];
},
);
</script>
7 changes: 4 additions & 3 deletions apps/admin/src/utils/http/axios/Axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export class VAxios {

// Request interceptor configuration processing
this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
// If cancel repeat request is turned on, then cancel repeat request is prohibited
const requestOptions = (config as unknown as any).requestOptions ?? this.options.requestOptions;
// If cancel repeat request is turned on, then cancel repeat request is prohibited
const requestOptions =
(config as unknown as any).requestOptions ?? this.options.requestOptions;
const ignoreCancelToken = requestOptions?.ignoreCancelToken ?? true;

!ignoreCancelToken && axiosCanceler.addPending(config);
Expand Down Expand Up @@ -202,7 +203,7 @@ export class VAxios {
if (config.cancelToken) {
conf.cancelToken = config.cancelToken;
}

if (config.signal) {
conf.signal = config.signal;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/views/system/dict/dict.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const columns: BasicColumn[] = [
},
{
title: '更新时间',
width: 150,
width: 160,
sorter: true,
dataIndex: 'updatedAt',
format: (text: string) => {
Expand Down
6 changes: 2 additions & 4 deletions apps/admin/src/views/system/user/user.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ export const columns: BasicColumn[] = [
{
title: '创建时间',
dataIndex: 'createdAt',
width: 165,
format: (text) => {
return formatToDateTime(text);
},
width: 160,
format: (text) => formatToDateTime(text),
},
];

Expand Down
6 changes: 2 additions & 4 deletions apps/admin/src/views/tools/storage/storage.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ export const columns: BasicColumn[] = [
{
title: '创建时间',
dataIndex: 'createdAt',
width: 150,
format: (text) => {
return formatToDateTime(text);
},
width: 160,
format: (text) => formatToDateTime(text),
},
];

Expand Down
20 changes: 3 additions & 17 deletions apps/api/.env
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
# app
APP_NAME = Nest Admin

# server port
PORT = 5001
APP_PORT = 5001
APP_LOCALE = zh-CN
WS_PORT = 5002
WS_PATH = ws-api

# global prefix, using in router、redis
GLOBAL_PREFIX = api

# specify id as the root administrator
ADMIN_ROLE_ID = 1
# user password salt
USER_PWD_SALT = kz!@#123
# user default password
USER_DEFAULT_PWD = a123456

# minimum internal requirements protect id
PROTECT_SYS_PERMMENU_MAX_ID = 1
PROTECT_SYS_DICTIONARY_MAX_ID = 1

# logger
LOGGER_LEVEL = verbose
LOGGER_MAX_FILES = 31
28 changes: 16 additions & 12 deletions apps/api/.env.development
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# token
# logger
LOGGER_LEVEL = debug

# security
JWT_SECRET = admin!@#123
JWT_EXPIRES = 86400
JWT_EXPIRE = 86400
REFRESH_TOKEN_SECRET = admin!@#123
REFRESH_TOKEN_EXPIRES = 2592000
REFRESH_TOKEN_EXPIRE = 2592000

# swagger
SWAGGER_ENABLE = true
SWAGGER_PATH = api-docs
SWAGGER_VERSION = 1.0

# db
DB_HOST = 127.0.0.1
Expand All @@ -19,12 +27,8 @@ REDIS_HOST = 127.0.0.1
REDIS_PASSWORD =
REDIS_DB = 0

# swagger
SWAGGER_ENABLE = true
SWAGGER_PATH = api-docs

# email
EMAIL_HOST = smtp.qq.com
EMAIL_PORT = 465
EMAIL_USER =
EMAIL_PASS =
# smtp
SMTP_HOST = smtp.qq.com
SMTP_PORT = 465
SMTP_USER =
SMTP_PASS =
36 changes: 19 additions & 17 deletions apps/api/.env.production
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# token
# logger
LOGGER_LEVEL = info

# security
JWT_SECRET = admin!@#123
JWT_EXPIRES = 86400
JWT_EXPIRE = 86400
REFRESH_TOKEN_SECRET = admin!@#123
REFRESH_TOKEN_EXPIRES = 2592000
REFRESH_TOKEN_EXPIRE = 2592000

# swagger
SWAGGER_ENABLE = true
SWAGGER_PATH = api-docs
SWAGGER_VERSION = 1.0

# db
DB_HOST = 127.0.0.1
DB_PORT = 3306
DB_DATABASE = kz-admin
DB_USERNAME = kz-admin
DB_DATABASE = qb360
DB_USERNAME = root
DB_PASSWORD = Aa123456
DB_SYNCHRONIZE = false
DB_SYNCHRONIZE = true
DB_LOGGING = ["error"]

# redis
Expand All @@ -19,14 +27,8 @@ REDIS_HOST = 127.0.0.1
REDIS_PASSWORD =
REDIS_DB = 0

# swagger
SWAGGER_ENABLE = false

# email
EMAIL_HOST = smtp.qq.com
EMAIL_PORT = 465
EMAIL_USER =
EMAIL_PASS =

# logger
LOGGER_LEVEL = warn
# smtp
SMTP_HOST = smtp.qq.com
SMTP_PORT = 465
SMTP_USER =
SMTP_PASS =
10 changes: 8 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"migration:revert": "typeorm -- migration:revert"
},
"dependencies": {
"@fastify/cookie": "^9.1.0",
"@fastify/multipart": "^8.0.0",
"@fastify/static": "^6.12.0",
"@liaoliaots/nestjs-redis": "^9.0.5",
Expand Down Expand Up @@ -68,7 +69,6 @@
"helmet": "^7.1.0",
"ioredis": "^5.3.2",
"lodash": "^4.17.21",
"log4js": "^6.9.1",
"mysql": "^2.18.1",
"nanoid": "^3.3.6",
"nodemailer": "^6.9.7",
Expand All @@ -83,7 +83,9 @@
"svg-captcha": "^1.4.0",
"systeminformation": "^5.21.16",
"typeorm": "^0.3.17",
"ua-parser-js": "^1.0.37"
"ua-parser-js": "^1.0.37",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.22",
Expand Down Expand Up @@ -135,5 +137,9 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"engines": {
"node": ">=18",
"pnpm": ">=8.1.0"
}
}
Loading

0 comments on commit 830246d

Please sign in to comment.