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

4
src/components/FileList.vue

@ -9,7 +9,7 @@
<div
class="img-box"
: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)"
></div>
@ -45,7 +45,7 @@
import { watch } from "vue";
const { VITE_API_URL } = "http://127.0.0.1:5173";
const { VITE_API_URL } = process.env;
const props = defineProps({
files: {
type: Array,

7
src/components/HolidayList.vue

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

4
src/components/MailDetail.vue

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

5
src/components/MailEtl.vue

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

8
src/components/ManageMail.vue

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

11
src/components/ManageUser.vue

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

3
src/components/Upload.vue

@ -1,7 +1,7 @@
<template>
<div>
<el-upload
action="/api/file/upload"
:action="`${VITE_API_URL}/file/upload`"
:headers=headers
multiple
:before-upload="beforeUpload"
@ -23,6 +23,7 @@
</div>
</template>
<script setup>
const { VITE_API_URL } = process.env;
import { useTokenStore } from '../stores/useTokenStore'
const tokens = useTokenStore()
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 { request } from '../util/axios_config';
import { ElMessage } from 'element-plus'
const { VITE_API_URL } = process.env;
const router = useRouter();
const logout = () => {
const url = VITE_API_URL +'/logout'
request({
url: 'api/logout',
url: url,
method: 'POST'
}).then((res) => {
if (res.data === 200) {

5
src/util/axios_config.js

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

19
vite.config.js

@ -1,4 +1,4 @@
import { defineConfig } from 'vite'
import { defineConfig , loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
@ -8,7 +8,13 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import svgLoader from 'vite-svg-loader'
// https://vitejs.dev/config/
export default defineConfig({
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd());
return defineConfig({
base: env.VITE_BASE,
define: {
'process.env': env
},
plugins: [
vue(),
svgLoader(),
@ -44,11 +50,16 @@ export default defineConfig({
server: {
host: '0.0.0.0',
proxy: {
'/api': {
'/admin-api': {
target: 'http://127.0.0.1:8083',
changeOrigin: true,
rewrite: (p) => p.replace(/^\/api/, '')
rewrite: (p) => p.replace(/^\/admin-api/, '')
}
}
}
})
}

Loading…
Cancel
Save