diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9acd837 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:1.27.0 +COPY dist/ /usr/share/nginx/html/ +COPY nginx.conf /etc/nginx/conf.d/default.conf +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' > /etc/timezone +RUN chmod -R 755 /usr/share/nginx/html/ diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..5e9ea06 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /usr/share/nginx/html; + + index index.html; + + server_name _; + + client_max_body_size 500M; + + location /study-agent/ { + alias /usr/share/nginx/html/; + try_files $uri $uri/ /study-agent/index.html; + } + + location /study-api/ { + proxy_pass http://host.docker.internal:8001/; + } + + location / { + try_files $uri $uri/ =404; + } +} diff --git a/package.json b/package.json index 0e908da..295f2c2 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vue-tsc -b && vite build", + "build": "vite build", "preview": "vite preview" }, "dependencies": { "@vueup/vue-quill": "^1.5.5", "axios": "^1.18.1", + "crypto-js": "^4.2.0", "dayjs": "^1.11.21", "element-plus": "^2.14.3", "filesize": "^11.0.22", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c3c3150..b143f7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: axios: specifier: ^1.18.1 version: 1.18.1 + crypto-js: + specifier: ^4.2.0 + version: 4.2.0 dayjs: specifier: ^1.11.21 version: 1.11.21 @@ -734,6 +737,9 @@ packages: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} + crypto-js@4.2.0: + resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==} + cssesc@3.0.0: resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} engines: {node: '>=4'} @@ -2817,6 +2823,8 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 + crypto-js@4.2.0: {} + cssesc@3.0.0: {} csstype@3.2.3: {} diff --git a/src/components/Library/LibraryFileDialog.vue b/src/components/Library/LibraryFileDialog.vue index 6b06ea4..32be6b1 100644 --- a/src/components/Library/LibraryFileDialog.vue +++ b/src/components/Library/LibraryFileDialog.vue @@ -121,6 +121,7 @@ import { QuillEditor } from '@vueup/vue-quill' import '@vueup/vue-quill/dist/vue-quill.snow.css' import { uploadLibraryFileApi } from '@/apis/library.ts' import { getModuleOptions } from '@/utils/libraryUtil.ts' +import { getFileExtension, getFileHashName } from '@/utils/file.ts' const libraryStore = useLibraryStore() const libraryFileFormRef = ref() @@ -166,9 +167,11 @@ const upload = async (options: UploadRequestOptions) => { const { file } = options libraryStore.currentFile.size = file.size libraryStore.currentFile.type = 'image' + const fileName = `${getFileHashName(file)}.${getFileExtension(file.name)}` const formData = new FormData() formData.append('file', file) + formData.append('filename', fileName) const loading = ElLoading.service({ lock: true, diff --git a/src/components/Library/LibraryFileList.vue b/src/components/Library/LibraryFileList.vue index 5feaf70..297e483 100644 --- a/src/components/Library/LibraryFileList.vue +++ b/src/components/Library/LibraryFileList.vue @@ -21,7 +21,7 @@ - + diff --git a/src/components/Practice/PracticeQuestion.vue b/src/components/Practice/PracticeQuestion.vue index a069d99..79e6a91 100644 --- a/src/components/Practice/PracticeQuestion.vue +++ b/src/components/Practice/PracticeQuestion.vue @@ -45,7 +45,7 @@ diff --git a/src/router/index.ts b/src/router/index.ts index 4bf9af6..8b55e0e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,4 +1,4 @@ -import { createRouter, createWebHistory } from 'vue-router' +import { createRouter, createWebHashHistory } from 'vue-router' import Layout from '../layout/index.vue' const routes = [ @@ -42,7 +42,7 @@ const routes = [ ] const router = createRouter({ - history: createWebHistory(), + history: createWebHashHistory(), routes }) diff --git a/src/stores/library.ts b/src/stores/library.ts index f804f2d..0615358 100644 --- a/src/stores/library.ts +++ b/src/stores/library.ts @@ -42,9 +42,12 @@ export const useLibraryStore = defineStore('library', { this.fileList = await queryLibraryFileListApi() this.subjectTree = getSubjectTree(this.fileList) this.subjectOptions = getSubjectOptions(this.subjectTree) - this.selectedSubject = this.subjectOptions[0].value - this.moduleOptions = getModuleOptions(this.subjectTree, this.selectedSubject) - this.selectedModule = this.moduleOptions[0].value + + if (this.subjectOptions.length > 0) { + this.selectedSubject = this.subjectOptions[0].value + this.moduleOptions = getModuleOptions(this.subjectTree, this.selectedSubject) + this.selectedModule = this.moduleOptions[0].value + } }, async queryFileById(id: number) { this.currentFile = await queryLibraryFileByIdApi(id) diff --git a/src/utils/file.ts b/src/utils/file.ts new file mode 100644 index 0000000..5f1cc2f --- /dev/null +++ b/src/utils/file.ts @@ -0,0 +1,13 @@ +import * as CryptoJS from 'crypto-js' + +const hashSHA256 = (message: string) => { + return CryptoJS.SHA256(message).toString(CryptoJS.enc.Hex) +} + +export const getFileHashName = (file: File) => { + return hashSHA256(`${file.name}_${file.lastModified}`) +} + +export const getFileExtension = (name: string) => { + return name.substring(name.lastIndexOf('.') + 1).toLowerCase() +} diff --git a/src/views/Mistakes.vue b/src/views/Mistakes.vue index ffa97f1..7593763 100644 --- a/src/views/Mistakes.vue +++ b/src/views/Mistakes.vue @@ -8,7 +8,7 @@
-
+
+ +
diff --git a/src/views/Practice.vue b/src/views/Practice.vue index 476e1f5..0272c35 100644 --- a/src/views/Practice.vue +++ b/src/views/Practice.vue @@ -12,7 +12,7 @@ - + diff --git a/vite.config.ts b/vite.config.ts index 9249864..073f2c8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,6 +14,7 @@ export default defineConfig({ } } }, + base: '/study-agent/', resolve: { // 配置路径别名 alias: {