Browse Source

管理端前端

厅长信箱
laishajiang 2 years ago
parent
commit
b15b847d52
  1. 2
      .env
  2. 2
      .env.dev
  3. 3
      .env.prod
  4. 4
      src/components/AddMail.vue
  5. 4
      src/components/FileList.vue
  6. 7
      src/components/HolidayList.vue
  7. 5
      src/components/LoginView.vue
  8. 4
      src/components/MailDetail.vue
  9. 5
      src/components/MailEtl.vue
  10. 8
      src/components/ManageMail.vue
  11. 11
      src/components/ManageUser.vue
  12. 3
      src/components/Upload.vue
  13. 4
      src/layout/Index.vue
  14. 5
      src/util/axios_config.js
  15. 91
      vite.config.js

2
.env

@ -0,0 +1,2 @@
VITE_BASE=/
VITE_API_URL=/admin-api

2
.env.dev

@ -0,0 +1,2 @@
VITE_BASE=/admin/
VITE_API_URL=/admin-api

3
.env.prod

@ -0,0 +1,3 @@
VITE_BASE=/
VITE_API_URL=/admin-api

4
src/components/AddMail.vue

@ -168,6 +168,7 @@ interface FormData {
fileList: any[]; fileList: any[];
attachments: String; attachments: String;
} }
const { VITE_API_URL } = process.env;
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
const form = ref({ const form = ref({
@ -239,8 +240,9 @@ const handleSubmit = () => {
// form.value.fileList = [] // form.value.fileList = []
// form.value.involvedDeptName = '' // form.value.involvedDeptName = ''
// }); // });
const url = VITE_API_URL +'/mailbox/add'
request({ request({
url: '/api/mailbox/add', url: url,
method: 'POST', method: 'POST',
data: {MailBo:form.value} , data: {MailBo:form.value} ,
headers: { 'Content-Type': 'application/json'} headers: { 'Content-Type': 'application/json'}

4
src/components/FileList.vue

@ -9,7 +9,7 @@
<div <div
class="img-box" class="img-box"
:style="{ :style="{
backgroundImage: `url(http://127.0.0.1:5173/api/file/stream/${item.filepath})`, backgroundImage: `url(${VITE_API_URL}/file/stream/${item.filepath})`,
}" }"
@click="filePreview(item)" @click="filePreview(item)"
></div> ></div>
@ -45,7 +45,7 @@
import { watch } from "vue"; import { watch } from "vue";
const { VITE_API_URL } = "http://127.0.0.1:5173"; const { VITE_API_URL } = process.env;
const props = defineProps({ const props = defineProps({
files: { files: {
type: Array, type: Array,

7
src/components/HolidayList.vue

@ -36,6 +36,7 @@
import { ref, onMounted, onBeforeMount } from 'vue'; import { ref, onMounted, onBeforeMount } from 'vue';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { request } from '../util/axios_config' import { request } from '../util/axios_config'
const { VITE_API_URL } = process.env;
const currenYear = ref(''); const currenYear = ref('');
const loading = ref(true); const loading = ref(true);
@ -46,8 +47,9 @@ const dayType = ref({
}); });
const getDateData = () => { const getDateData = () => {
const url = VITE_API_URL +'/outer/holiday/show-holiday'
request({ request({
url: '/api/outer/holiday/show-holiday', url: url,
method: 'GET' method: 'GET'
}).then(res => { }).then(res => {
dayType.value = res.data; dayType.value = res.data;
@ -92,8 +94,9 @@ const searchHoliday = () => {
const refreshHoliday = () => { const refreshHoliday = () => {
loading.value = true; loading.value = true;
const url = VITE_API_URL +'/outer/holiday/refresh-holiday'
request({ request({
url: '/api/outer/holiday/refresh-holiday', url: url,
method: 'POST', method: 'POST',
data: { year: currenYear.value }, data: { year: currenYear.value },
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }

5
src/components/LoginView.vue

@ -24,7 +24,7 @@ import { request } from '../util/axios_config'
import router from '../router' import router from '../router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useTokenStore } from '../stores/useTokenStore' import { useTokenStore } from '../stores/useTokenStore'
const { VITE_API_URL } = process.env;
const tokens = useTokenStore() const tokens = useTokenStore()
const login = reactive({ const login = reactive({
@ -53,8 +53,9 @@ const inputCheck = () => {
// } // }
const loginIn = () => { const loginIn = () => {
const url = VITE_API_URL +'/login'
request({ request({
url: '/api/login', url: url,
method: 'POST', method: 'POST',
data: login, data: login,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }

4
src/components/MailDetail.vue

@ -47,6 +47,7 @@
import { ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import router from '../router'; import router from '../router';
import { request } from '../util/axios_config' import { request } from '../util/axios_config'
const { VITE_API_URL } = process.env;
const mailID = router.currentRoute.value.params.id; const mailID = router.currentRoute.value.params.id;
const form = ref({ const form = ref({
@ -60,8 +61,9 @@ const form = ref({
}); });
onMounted(() => { onMounted(() => {
const url = VITE_API_URL +'/mailbox/detail'
request({ request({
url: '/api/mailbox/detail', url: url,
method: 'POST', method: 'POST',
data: { id: mailID } data: { id: mailID }
}).then(res => { }).then(res => {

5
src/components/MailEtl.vue

@ -81,7 +81,7 @@ import { request } from '../util/axios_config'
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import router from '../router'; import router from '../router';
const MailTab = ref('mail_etl') const MailTab = ref('mail_etl')
const { VITE_API_URL } = process.env;
const options = [ const options = [
{ {
value: 'mail_etl', value: 'mail_etl',
@ -135,8 +135,9 @@ const handleResponse = (response) => {
const makeRequest = (requestData, callback) => { const makeRequest = (requestData, callback) => {
const data = JSON.stringify(requestData) const data = JSON.stringify(requestData)
const url = VITE_API_URL +'/mailetl/list-submit'
request({ request({
url: 'api/mailetl/list-submit', url: url,
method: 'POST', method: 'POST',
data: data, data: data,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }

8
src/components/ManageMail.vue

@ -110,7 +110,7 @@ import router from '../router';
import AddMail from "../components/AddMail.vue"; import AddMail from "../components/AddMail.vue";
const loading = ref(true); const loading = ref(true);
const { VITE_API_URL } = process.env;
const form = ref({ const form = ref({
date: '', date: '',
@ -152,8 +152,9 @@ const handleResponse = (response) => {
const makeRequest = (requestData, callback) => { const makeRequest = (requestData, callback) => {
const data = JSON.stringify(requestData) const data = JSON.stringify(requestData)
const url = VITE_API_URL +'/mailbox/list-submit'
request({ request({
url: 'api/mailbox/list-submit', url: url,
method: 'POST', method: 'POST',
data: data, data: data,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
@ -224,8 +225,9 @@ const out = () => {
pageData: pageData.value pageData: pageData.value
} }
const data = JSON.stringify(requestData) const data = JSON.stringify(requestData)
const url = VITE_API_URL +'/mailbox/exportexcel'
request({ request({
url: 'api/mailbox/exportexcel', url: url,
method: 'POST', method: 'POST',
data: data, data: data,
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },

11
src/components/ManageUser.vue

@ -101,7 +101,7 @@
import { request } from '../util/axios_config' import { request } from '../util/axios_config'
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const { VITE_API_URL } = process.env;
const loading = ref(true); const loading = ref(true);
const form = ref({ const form = ref({
date: '', date: '',
@ -126,8 +126,9 @@ const pageData = ref({
}) })
const getData = (data) => { const getData = (data) => {
const url = VITE_API_URL +'/user/list-submit'
request({ request({
url: 'api/user/list-submit', url: url,
method: 'POST', method: 'POST',
data: data, data: data,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
@ -159,8 +160,9 @@ const flexColumnWidth = (label, prop) => {
} }
const handleDelete = (index) => { const handleDelete = (index) => {
const url = VITE_API_URL +'/user/delete-user'
request({ request({
url: 'api/user/delete-user', url: url,
method: 'POST', method: 'POST',
data: { id: tableData.value[index - 1].id }, data: { id: tableData.value[index - 1].id },
}).then(function (response) { }).then(function (response) {
@ -220,8 +222,9 @@ const newUser = ref(false)
const submitNewUser = () => { const submitNewUser = () => {
const requestData = newForm.value const requestData = newForm.value
const data = JSON.stringify(requestData) const data = JSON.stringify(requestData)
const url = VITE_API_URL +'/user/add-user'
request({ request({
url: 'api/user/add-user', url: url,
method: 'POST', method: 'POST',
data: data, data: data,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }

3
src/components/Upload.vue

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<el-upload <el-upload
action="/api/file/upload" :action="`${VITE_API_URL}/file/upload`"
:headers=headers :headers=headers
multiple multiple
:before-upload="beforeUpload" :before-upload="beforeUpload"
@ -23,6 +23,7 @@
</div> </div>
</template> </template>
<script setup> <script setup>
const { VITE_API_URL } = process.env;
import { useTokenStore } from '../stores/useTokenStore' import { useTokenStore } from '../stores/useTokenStore'
const tokens = useTokenStore() const tokens = useTokenStore()
const accessToken = tokens.access_token; const accessToken = tokens.access_token;

4
src/layout/Index.vue

@ -42,12 +42,14 @@ import { useRouter } from "vue-router";
import { useTokenStore } from '../stores/useTokenStore'; import { useTokenStore } from '../stores/useTokenStore';
import { request } from '../util/axios_config'; import { request } from '../util/axios_config';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const { VITE_API_URL } = process.env;
const router = useRouter(); const router = useRouter();
const logout = () => { const logout = () => {
const url = VITE_API_URL +'/logout'
request({ request({
url: 'api/logout', url: url,
method: 'POST' method: 'POST'
}).then((res) => { }).then((res) => {
if (res.data === 200) { if (res.data === 200) {

5
src/util/axios_config.js

@ -2,6 +2,7 @@ import axios from 'axios'
import { getActivePinia } from 'pinia' import { getActivePinia } from 'pinia'
import { useTokenStore } from "@/stores/useTokenStore"; import { useTokenStore } from "@/stores/useTokenStore";
import router from "@/router"; import router from "@/router";
const { VITE_API_URL } = process.env;
axios.defaults.baseURL = '' axios.defaults.baseURL = ''
axios.defaults.timeout = 10000 axios.defaults.timeout = 10000
@ -42,10 +43,12 @@ axios.interceptors.response.use(response => {
// 401 错误,说明 access_token 过期了,需要用 refresh_token 来刷新 // 401 错误,说明 access_token 过期了,需要用 refresh_token 来刷新
if (error.response && error.response.status === 401) { if (error.response && error.response.status === 401) {
const refreshToken = tokens.refresh_token const refreshToken = tokens.refresh_token
if (refreshToken) { if (refreshToken) {
try { try {
const url = VITE_API_URL +'/refresh-token'
// console.log("refresh-token-req:" + refreshToken) // console.log("refresh-token-req:" + refreshToken)
const res = await axios.create().post('api/refresh-token', { refreshToken: refreshToken }) const res = await axios.create().post(url, { refreshToken: refreshToken })
// console.log("refresh-token-res:" + JSON.stringify(res)) // console.log("refresh-token-res:" + JSON.stringify(res))
// 如果刷新成功,就更新本地存储中的 token,并且重新发送之前失败的请求 // 如果刷新成功,就更新本地存储中的 token,并且重新发送之前失败的请求
if (res.data && res.data.accessToken) { if (res.data && res.data.accessToken) {

91
vite.config.js

@ -1,4 +1,4 @@
import { defineConfig } from 'vite' import { defineConfig , loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import path from 'path' import path from 'path'
@ -8,47 +8,58 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import svgLoader from 'vite-svg-loader' import svgLoader from 'vite-svg-loader'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default ({ mode }) => {
plugins: [ const env = loadEnv(mode, process.cwd());
vue(), return defineConfig({
svgLoader(), base: env.VITE_BASE,
AutoImport({ define: {
imports: [ 'process.env': env
'vue'
],
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver({
importStyle: "sass"
})],
}),
],
resolve: {
// https://cn.vitejs.dev/config/#resolve-alias
alias: {
// 设置别名
'~/': `${path.resolve(__dirname, 'src')}/`,
'@': path.resolve(__dirname, './src/')
}, },
// https://cn.vitejs.dev/config/#resolve-extensions plugins: [
extensions: ['.js'] vue(),
}, svgLoader(),
css: { AutoImport({
preprocessorOptions: { imports: [
scss: { 'vue'
additionalData: `@use "src/assets/style/element.scss" as *;` ],
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver({
importStyle: "sass"
})],
}),
],
resolve: {
// https://cn.vitejs.dev/config/#resolve-alias
alias: {
// 设置别名
'~/': `${path.resolve(__dirname, 'src')}/`,
'@': path.resolve(__dirname, './src/')
}, },
// https://cn.vitejs.dev/config/#resolve-extensions
extensions: ['.js']
}, },
}, css: {
server: { preprocessorOptions: {
host: '0.0.0.0', scss: {
proxy: { additionalData: `@use "src/assets/style/element.scss" as *;`
'/api': { },
target: 'http://127.0.0.1:8083', },
changeOrigin: true, },
rewrite: (p) => p.replace(/^\/api/, '') server: {
host: '0.0.0.0',
proxy: {
'/admin-api': {
target: 'http://127.0.0.1:8083',
changeOrigin: true,
rewrite: (p) => p.replace(/^\/admin-api/, '')
}
} }
} }
} })
})
}

Loading…
Cancel
Save