API修改
This commit is contained in:
parent
2f36aa1588
commit
964feff08c
5
.env.development
Normal file
5
.env.development
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
NODE_ENV='development'
|
||||||
|
|
||||||
|
VITE_API_URL='http://www.hylszsh.cn/Api/'
|
||||||
|
|
||||||
|
VITE_OSS_URL='http://www.hylszsh.cn/Api/StaticFiles/'
|
5
.env.production
Normal file
5
.env.production
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
NODE_ENV='production'
|
||||||
|
|
||||||
|
VITE_API_URL='http://www.hylszsh.cn/Api/'
|
||||||
|
|
||||||
|
VITE_OSS_URL='http://www.hylszsh.cn/Api/StaticFiles/'
|
@ -8,12 +8,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.1",
|
"@element-plus/icons-vue": "^2.3.1",
|
||||||
"axios": "^1.7.9",
|
|
||||||
"canvas2image": "^1.0.5",
|
"canvas2image": "^1.0.5",
|
||||||
"element-plus": "^2.9.4",
|
"element-plus": "^2.9.4",
|
||||||
"html2canvas": "^1.4.1",
|
"html2canvas": "^1.4.1",
|
||||||
"jquery": "^3.7.1",
|
"jquery": "^3.7.1",
|
||||||
"pan.template.h5": "file:",
|
|
||||||
"postcss-px-to-viewport": "^1.1.1",
|
"postcss-px-to-viewport": "^1.1.1",
|
||||||
"vant": "^4.9.9",
|
"vant": "^4.9.9",
|
||||||
"vue": "^3.2.45",
|
"vue": "^3.2.45",
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
import http from '../utils/http';
|
|
||||||
|
|
||||||
const CommonAPI = {
|
|
||||||
Post(name, data, index, size) {
|
|
||||||
if (index)
|
|
||||||
return http.post(`Common/${name}`, { data: data, PageIndex: index, PageSize: size });
|
|
||||||
return http.post(`Common/${name}`, { data: data });
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
export default CommonAPI;
|
|
@ -1,17 +0,0 @@
|
|||||||
import http from '../utils/http'
|
|
||||||
|
|
||||||
const MemberAPI = {
|
|
||||||
WXAuthorize(data) {
|
|
||||||
return http.get('Wechat/Authorize', { path: data });
|
|
||||||
},
|
|
||||||
Login(data) {
|
|
||||||
return http.get('Auth/Token', data);
|
|
||||||
},
|
|
||||||
Post(name, data, index, size) {
|
|
||||||
if (index)
|
|
||||||
return http.post(`Member/${name}`, { data: data, PageIndex: index, PageSize: size });
|
|
||||||
return http.post(`Member/${name}`, { data: data });
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
export default MemberAPI;
|
|
@ -1,21 +0,0 @@
|
|||||||
import http from '../utils/http'
|
|
||||||
|
|
||||||
const PayAPI = {
|
|
||||||
PayInfo(data) {
|
|
||||||
return http.post('Member/PayInfo', { data: data });
|
|
||||||
},
|
|
||||||
WalletPay(data) {
|
|
||||||
return http.post('Member/WalletPay', { data, data });
|
|
||||||
},
|
|
||||||
Wechat_JS(data) {
|
|
||||||
return http.get('Pay/Wechat_JS', data);
|
|
||||||
},
|
|
||||||
AliPay_H5(data) {
|
|
||||||
return http.get('Pay/AliPay_H5', data);
|
|
||||||
},
|
|
||||||
// Wechat_Mini(data) {
|
|
||||||
// return http.get('Pay/Wechat_Mini', data);
|
|
||||||
// },
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PayAPI;
|
|
31
src/main.js
31
src/main.js
@ -253,12 +253,31 @@ app.config.globalProperties.$goIndex = () => {
|
|||||||
app.config.globalProperties.$CheckStates = [{ label: '待审核', color: 'primary' }, { label: '已通过', color: 'success' }, { label: '已拒绝', color: 'danger' }];
|
app.config.globalProperties.$CheckStates = [{ label: '待审核', color: 'primary' }, { label: '已通过', color: 'success' }, { label: '已拒绝', color: 'danger' }];
|
||||||
|
|
||||||
// api
|
// api
|
||||||
import MemberAPI from './api/member';
|
app.config.globalProperties.$api = {
|
||||||
import CommonAPI from './api/common';
|
post(e, data) {
|
||||||
import PayAPI from './api/pay';
|
return new Promise((resolve, reject) => {
|
||||||
app.config.globalProperties.$MemberAPI = MemberAPI;
|
fetch(`${import.meta.env.VITE_API_URL}${e}`, {
|
||||||
app.config.globalProperties.$CommonAPI = CommonAPI;
|
method: 'POST',
|
||||||
app.config.globalProperties.$PayAPI = PayAPI;
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
}).then(rep => {
|
||||||
|
rep.json().then(data => {
|
||||||
|
if (data.Code == 0) {
|
||||||
|
resolve(data.Data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
reject(data.Message);
|
||||||
|
}).catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
app.config.globalProperties.$isWechat = () => { return navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger' };
|
app.config.globalProperties.$isWechat = () => { return navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger' };
|
||||||
app.config.globalProperties.$isWechatMini = () => { return window.__wxjs_environment == 'miniprogram' };
|
app.config.globalProperties.$isWechatMini = () => { return window.__wxjs_environment == 'miniprogram' };
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import {request} from './request'
|
|
||||||
const http = {
|
|
||||||
get(url, params) {
|
|
||||||
const config = {
|
|
||||||
method: 'get',
|
|
||||||
url: url
|
|
||||||
}
|
|
||||||
if (params) config.params = params
|
|
||||||
return request(config)
|
|
||||||
},
|
|
||||||
post(url, params) {
|
|
||||||
const config = {
|
|
||||||
method: 'post',
|
|
||||||
url: url
|
|
||||||
}
|
|
||||||
if (params) config.data = params
|
|
||||||
return request(config)
|
|
||||||
},
|
|
||||||
put(url, params) {
|
|
||||||
const config = {
|
|
||||||
method: 'put',
|
|
||||||
url: url
|
|
||||||
}
|
|
||||||
if (params) config.params = params
|
|
||||||
return request(config)
|
|
||||||
},
|
|
||||||
delete(url, params) {
|
|
||||||
const config = {
|
|
||||||
method: 'post',
|
|
||||||
url: url
|
|
||||||
}
|
|
||||||
if (params) config.params = params
|
|
||||||
return request(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default http
|
|
@ -1,68 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
export function request(config) {
|
|
||||||
const instance = axios.create({
|
|
||||||
baseURL: import.meta.env.VITE_API_URL,
|
|
||||||
timeout: 60000,
|
|
||||||
})
|
|
||||||
instance.interceptors.request.use(config => {
|
|
||||||
config.headers['Member-Token'] = localStorage.getItem('member_token') || '';
|
|
||||||
config.headers['Content-Type'] = 'application/json';
|
|
||||||
if (config.data) {
|
|
||||||
config.data.ts = Date.now();
|
|
||||||
} else {
|
|
||||||
config.data = {
|
|
||||||
data: {},
|
|
||||||
ts: Date.now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}, error => {
|
|
||||||
return Promise.error(error)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
instance.interceptors.response.use(rep => {
|
|
||||||
if (rep.data.errcode) {
|
|
||||||
if (rep.data.errcode == 41000) {
|
|
||||||
localStorage.setItem('member_token', rep.data.access_token);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
axios.request(rep.config).then(data => {
|
|
||||||
if (data.data.errcode)
|
|
||||||
reject(data.data);
|
|
||||||
else
|
|
||||||
resolve(data.data);
|
|
||||||
}).catch(err => {
|
|
||||||
if (err.isAxiosError) {
|
|
||||||
switch (err.code) {
|
|
||||||
case 'ERR_NETWORK': reject('服务器连接失败');
|
|
||||||
case 'ECONNABORTED': reject('网络繁忙,请重试');
|
|
||||||
default: reject(err.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if ([41001, 40001, 40002].includes(rep.data.errcode)) {
|
|
||||||
localStorage.removeItem('member_token');
|
|
||||||
location.replace('#/Login');
|
|
||||||
return Promise.reject({ errcode: rep.data.errcode, errmsg: '请先登录' });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return Promise.reject(rep.data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return Promise.resolve(rep.data);
|
|
||||||
}, error => {
|
|
||||||
if (error.isAxiosError) {
|
|
||||||
switch (error.code) {
|
|
||||||
case 'ERR_NETWORK': return Promise.reject('服务器连接失败');
|
|
||||||
case 'ECONNABORTED': return Promise.reject('网络繁忙,请重试');
|
|
||||||
default: return Promise.reject(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.reject(error)
|
|
||||||
})
|
|
||||||
return instance(config);
|
|
||||||
}
|
|
||||||
export default request
|
|
@ -114,6 +114,10 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.scrollDiy();
|
this.scrollDiy();
|
||||||
|
this.$api.post('Carousel/Get', { Type: 1 }).then(data => {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -1,19 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<router-view v-slot="{ Component }">
|
<router-view v-slot="{ Component }">
|
||||||
<keep-alive :include="cacheRoutes">
|
<keep-alive :include="cacheRoutes">
|
||||||
<component :is="Component" :key="$route.fullPath" @changeTabbar="changeActive" @updateCart="updateCart" />
|
<component :is="Component" :key="$route.fullPath" @changeTabbar="changeActive" />
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</router-view>
|
</router-view>
|
||||||
<!-- <van-tabbar v-model="data.DefaultActive" placeholder @change="changeActive" active-color="#f53b32"
|
|
||||||
inactive-color="#666" fixed>
|
|
||||||
<van-tabbar-item v-for="(item, index) in data.Tabbars" :name="item.Name" :badge="getBadge(item)" :dot="item.Dot"
|
|
||||||
@click="refresh(item.Name)">
|
|
||||||
<span>{{ item.Label }}</span>
|
|
||||||
<template #icon="props">
|
|
||||||
<img :src="props.active ? item.Icon_Active : item.Icon_Inactive" />
|
|
||||||
</template>
|
|
||||||
</van-tabbar-item>
|
|
||||||
</van-tabbar> -->
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -25,30 +15,17 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.init();
|
this.init();
|
||||||
},
|
},
|
||||||
beforeRouteEnter() {
|
|
||||||
if (this)
|
|
||||||
this.updateCart();
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
getBadge() {
|
|
||||||
return (e) => {
|
|
||||||
if (e.Name == 'Cart')
|
|
||||||
return this.cartQty || '';
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
data: {},
|
data: {},
|
||||||
sysConfig: {},
|
sysConfig: {},
|
||||||
cartQty: 0,
|
|
||||||
cacheRoutes: this.$router.getRoutes().filter(x => x.meta.cache).map(x => x.name),
|
cacheRoutes: this.$router.getRoutes().filter(x => x.meta.cache).map(x => x.name),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
if (this.$route.name = '/')
|
||||||
|
location.replace('#/Home');
|
||||||
},
|
},
|
||||||
refresh(e) {
|
refresh(e) {
|
||||||
if (e == this.data.DefaultActive)
|
if (e == this.data.DefaultActive)
|
||||||
@ -60,10 +37,5 @@ export default {
|
|||||||
location.reload();
|
location.reload();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
beforeRouteEnter(to, from, next) {
|
|
||||||
next(vm => {
|
|
||||||
vm.updateCart();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user