master
xingyy 9 months ago
parent a76d89c31b
commit d134d3120e

@ -3,17 +3,9 @@
<script setup> <script setup>
import {onLaunch} from "@dcloudio/uni-app"; import {onLaunch} from "@dcloudio/uni-app";
onLaunch(()=>{ onLaunch(()=>{
console.log('onLaunch') console.log('onLaunch')
/* if (uni.getStorageSync('token')){
uni.navigateTo({
url: '/pages/index/index'
})
}else {
uni.navigateTo({
url: '/pages/login/index'
})
}*/
}) })
</script> </script>
<style> <style>

@ -26,9 +26,6 @@ const groupObjectsByNumberKeys=(obj)=> {
} }
const result = ref(groupObjectsByNumberKeys(slots)) const result = ref(groupObjectsByNumberKeys(slots))
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.content2{ .content2{
margin-top: 38rpx; margin-top: 38rpx;

@ -1,18 +1,42 @@
import uniReq from '@/http/init' import uniReq from '@/http/init'
export const login=(data)=> {
export const login = (data) => {
return uniReq.post({ return uniReq.post({
url: '/api/user/login/wx/telnum', url: '/api/user/login/wx/telnum',
data data
}) })
} }
export const getInfo=()=> { export const getInfo = () => {
return uniReq.post({ return uniReq.post({
url: '/api/user/info' url: '/api/user/info'
}) })
} }
export const ticketlist=(data)=> { export const ticketlist = (data) => {
return uniReq.post({ return uniReq.post({
url: '/ticket/ticketList', url: '/ticket/ticketList',
data data
}) })
} }
export const upload = (data) => {
return uniReq.upload({
name: data.name,
url: '/api/common/upload',
filePath: data.filePath,
interceptor: {
response(res) {
try {
return JSON.parse(res.data)
} catch (e) {
return e
}
}
}
})
}
export const updateAvatar = (data) => {
return uniReq.post({
url: '/api/user/update',
data
})
}

@ -1,8 +1,7 @@
import {uniRequest} from "@/http/main"; import {uniRequest} from "@/http/main";
const TEST_URL='http://172.16.100.93:9052'
export default uniRequest.created({ export default uniRequest.created({
baseUrl: 'http://172.16.100.93:9052', baseUrl: TEST_URL,
// baseUrl: 'http://192.168.88.122:9021',
header: { header: {
Authorization: uni.getStorageSync('token') ?? '' Authorization: uni.getStorageSync('token') ?? ''
}, },
@ -18,6 +17,11 @@ export default uniRequest.created({
return config return config
}, },
response(response) { response(response) {
uni.showToast({
title: response.data.msg,
icon: 'none',
duration: 3000
})
uni.hideLoading() uni.hideLoading()
return response.data return response.data
} }

@ -37,11 +37,30 @@ interface RequestOptions {
enableCookie?: boolean, enableCookie?: boolean,
cloudCache?: object | boolean, cloudCache?: object | boolean,
defer?: boolean, defer?: boolean,
interceptor?:{ interceptor?: {
request?: RequestInterceptor, request?: RequestInterceptor,
response?: ResponseInterceptor response?: ResponseInterceptor
} }
} }
interface UploadOptions {
url: string,
baseUrl?: string,
files?: File[],
fileType?: 'image' | 'video' | 'audio',
file?: File,
filePath?: string,
name?: string,
header?: object,
timeout?: number,
formData?: object,
interceptor?: {
request?: (config: UploadOptions) => UploadOptions,
response?: (response: any) => any;
}
}
type RequestInterceptor = (config: RequestOptions) => RequestOptions; type RequestInterceptor = (config: RequestOptions) => RequestOptions;
type ResponseInterceptor = (response: any) => any; type ResponseInterceptor = (response: any) => any;
@ -49,6 +68,7 @@ class uniRequest {
baseUrl?: string; baseUrl?: string;
defaultHeader: Record<string, string>; defaultHeader: Record<string, string>;
interceptors: { request?: RequestInterceptor; response?: ResponseInterceptor }; interceptors: { request?: RequestInterceptor; response?: ResponseInterceptor };
constructor(request: RequestOptions) { constructor(request: RequestOptions) {
this.baseUrl = request.baseUrl; this.baseUrl = request.baseUrl;
this.defaultHeader = { this.defaultHeader = {
@ -57,6 +77,7 @@ class uniRequest {
}; };
this.interceptors = {request: request.interceptor?.request, response: request.interceptor?.response}; this.interceptors = {request: request.interceptor?.request, response: request.interceptor?.response};
} }
setBaseUrl(baseUrl: string): void { setBaseUrl(baseUrl: string): void {
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
} }
@ -64,9 +85,11 @@ class uniRequest {
setDefaultHeader(header: Record<string, string>): void { setDefaultHeader(header: Record<string, string>): void {
this.defaultHeader = header; this.defaultHeader = header;
} }
static created(options: RequestOptions){
static created(options: RequestOptions) {
return new uniRequest(options); return new uniRequest(options);
} }
request(options: RequestOptions): Promise<any> { request(options: RequestOptions): Promise<any> {
options = this.buildRequestOptions(options) options = this.buildRequestOptions(options)
options = options || {}; options = options || {};
@ -85,7 +108,7 @@ class uniRequest {
uni.request({ uni.request({
...options, ...options,
success: (res) => { success: (res) => {
const response = this.handleResponse(res,options); const response = this.handleResponse(res, options);
resolve(response); resolve(response);
}, },
fail: (err) => { fail: (err) => {
@ -96,15 +119,20 @@ class uniRequest {
}); });
} }
private handleResponse(response: any,options:RequestOptions): any { private handleResponse(response: any, options: RequestOptions): any {
if (options.interceptor?.response){ if (options.interceptor?.response) {
response = options.interceptor?.response(response); response = options.interceptor?.response(response);
}else if (this.interceptors?.response) { } else if (this.interceptors?.response) {
response = this.interceptors?.response(response); response = this.interceptors?.response(response);
} }
return response return response
} }
private handleUploadResponse(res: any, options: UploadOptions){
if (options.interceptor?.response){
res = options.interceptor?.response(res);
}
return res
}
private handleError(error: any): any { private handleError(error: any): any {
throw error; throw error;
} }
@ -122,6 +150,23 @@ class uniRequest {
options.method = "GET"; options.method = "GET";
return this.request(this.buildRequestOptions(options)); return this.request(this.buildRequestOptions(options));
} }
upload(options: UploadOptions) {
options.url = `${options.baseUrl ?? this.baseUrl}${options.url}`;
if (typeof options.interceptor?.request==='function'){
options = options.interceptor.request(options);
}
return new Promise((resolve, reject) => {
uni.uploadFile({
...options,
success: (res) => {
resolve(this.handleUploadResponse(res, options))
},
fail(res){
reject(res)
}
});
})
}
private buildRequestOptions(options: RequestOptions): RequestOptions { private buildRequestOptions(options: RequestOptions): RequestOptions {
if (options.params && Object.keys(options.params).length > 0) { if (options.params && Object.keys(options.params).length > 0) {

@ -6,7 +6,6 @@
</view> </view>
</div> </div>
</template> </template>
<script setup > <script setup >
import { ref, getCurrentInstance } from "vue"; import { ref, getCurrentInstance } from "vue";
import {login,getInfo} from "@/http/apis"; import {login,getInfo} from "@/http/apis";
@ -17,7 +16,6 @@ code:data.detail.code
}) })
if (res.code===200){ if (res.code===200){
uni.setStorageSync('token',res.data.token); uni.setStorageSync('token',res.data.token);
console.log(uni.getStorageSync('token'),'11111')
getUserInfo() getUserInfo()
} }
} }
@ -31,7 +29,6 @@ const res=await getInfo()
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.main { .main {
background: url("https://cdns.fontree.cn/fonchain-main/prod/image/default/artwork/3f70cf7f-4017-42a6-9276-bf854f57f78d.png"); background: url("https://cdns.fontree.cn/fonchain-main/prod/image/default/artwork/3f70cf7f-4017-42a6-9276-bf854f57f78d.png");

@ -47,7 +47,6 @@
<image src="../../static/zu762@3x.png" alt=""/> <image src="../../static/zu762@3x.png" alt=""/>
</div> </div>
</div> </div>
<div class="wrap1"> <div class="wrap1">
<div class="wrap1_1 verified">已核销</div> <div class="wrap1_1 verified">已核销</div>
<div class="wrap1_2"> <div class="wrap1_2">
@ -66,7 +65,6 @@
<script setup> <script setup>
import {ref} from 'vue' import {ref} from 'vue'
import {onShow} from "@dcloudio/uni-app"; import {onShow} from "@dcloudio/uni-app";
const modeClass = ref('') const modeClass = ref('')
const show = ref(true) const show = ref(true)
const userInfo = ref(uni.getStorageSync('userInfo') ?? {}) const userInfo = ref(uni.getStorageSync('userInfo') ?? {})

@ -2,7 +2,7 @@
<div class="large-container"> <div class="large-container">
<div class="content1"> <div class="content1">
<div class="wrap1"> <div class="wrap1">
<image src="../../static/zy68.png"></image> <image :src="currentAvatar"></image>
</div> </div>
<div class="wrap2"> <div class="wrap2">
<div class="wrap2_1">恢复默认头像</div> <div class="wrap2_1">恢复默认头像</div>
@ -38,10 +38,35 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import {updateAvatar, upload} from "@/http/apis";
import {nextTick, ref} from 'vue'
const currentAvatar=ref('')
const changeAvatar=()=>{ const changeAvatar=()=>{
uni.uploadFile({
}) uni.chooseImage({
count:1,
success:async (res)=>{
const res1= await upload({
name:'file',
filePath:res.tempFilePaths[0]
})
currentAvatar.value=res1.data.path
reqAvatar()
}
})
}
const reqAvatar=async ()=>{
const res= await updateAvatar({
avatar:currentAvatar.value
})
if (res.code===200) {
uni.showToast({
title: '更换头像成功',
icon: 'success',
duration: 200
})
}
console.log(res,'res')
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

Loading…
Cancel
Save