submit
This commit is contained in:
parent
a76d89c31b
commit
d134d3120e
10
src/App.vue
10
src/App.vue
@ -3,17 +3,9 @@
|
||||
<script setup>
|
||||
import {onLaunch} from "@dcloudio/uni-app";
|
||||
|
||||
|
||||
onLaunch(()=>{
|
||||
console.log('onLaunch')
|
||||
/* if (uni.getStorageSync('token')){
|
||||
uni.navigateTo({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}*/
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
|
@ -26,9 +26,6 @@ const groupObjectsByNumberKeys=(obj)=> {
|
||||
}
|
||||
const result = ref(groupObjectsByNumberKeys(slots))
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style scoped lang="scss">
|
||||
.content2{
|
||||
margin-top: 38rpx;
|
||||
|
@ -1,18 +1,42 @@
|
||||
import uniReq from '@/http/init'
|
||||
export const login=(data)=> {
|
||||
|
||||
export const login = (data) => {
|
||||
return uniReq.post({
|
||||
url: '/api/user/login/wx/telnum',
|
||||
data
|
||||
})
|
||||
}
|
||||
export const getInfo=()=> {
|
||||
export const getInfo = () => {
|
||||
return uniReq.post({
|
||||
url: '/api/user/info'
|
||||
})
|
||||
}
|
||||
export const ticketlist=(data)=> {
|
||||
export const ticketlist = (data) => {
|
||||
return uniReq.post({
|
||||
url: '/ticket/ticketList',
|
||||
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";
|
||||
|
||||
const TEST_URL='http://172.16.100.93:9052'
|
||||
export default uniRequest.created({
|
||||
baseUrl: 'http://172.16.100.93:9052',
|
||||
// baseUrl: 'http://192.168.88.122:9021',
|
||||
baseUrl: TEST_URL,
|
||||
header: {
|
||||
Authorization: uni.getStorageSync('token') ?? ''
|
||||
},
|
||||
@ -18,6 +17,11 @@ export default uniRequest.created({
|
||||
return config
|
||||
},
|
||||
response(response) {
|
||||
uni.showToast({
|
||||
title: response.data.msg,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
uni.hideLoading()
|
||||
return response.data
|
||||
}
|
||||
|
@ -37,11 +37,30 @@ interface RequestOptions {
|
||||
enableCookie?: boolean,
|
||||
cloudCache?: object | boolean,
|
||||
defer?: boolean,
|
||||
interceptor?:{
|
||||
interceptor?: {
|
||||
request?: RequestInterceptor,
|
||||
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 ResponseInterceptor = (response: any) => any;
|
||||
|
||||
@ -49,6 +68,7 @@ class uniRequest {
|
||||
baseUrl?: string;
|
||||
defaultHeader: Record<string, string>;
|
||||
interceptors: { request?: RequestInterceptor; response?: ResponseInterceptor };
|
||||
|
||||
constructor(request: RequestOptions) {
|
||||
this.baseUrl = request.baseUrl;
|
||||
this.defaultHeader = {
|
||||
@ -57,6 +77,7 @@ class uniRequest {
|
||||
};
|
||||
this.interceptors = {request: request.interceptor?.request, response: request.interceptor?.response};
|
||||
}
|
||||
|
||||
setBaseUrl(baseUrl: string): void {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
@ -64,9 +85,11 @@ class uniRequest {
|
||||
setDefaultHeader(header: Record<string, string>): void {
|
||||
this.defaultHeader = header;
|
||||
}
|
||||
static created(options: RequestOptions){
|
||||
|
||||
static created(options: RequestOptions) {
|
||||
return new uniRequest(options);
|
||||
}
|
||||
|
||||
request(options: RequestOptions): Promise<any> {
|
||||
options = this.buildRequestOptions(options)
|
||||
options = options || {};
|
||||
@ -85,7 +108,7 @@ class uniRequest {
|
||||
uni.request({
|
||||
...options,
|
||||
success: (res) => {
|
||||
const response = this.handleResponse(res,options);
|
||||
const response = this.handleResponse(res, options);
|
||||
resolve(response);
|
||||
},
|
||||
fail: (err) => {
|
||||
@ -96,15 +119,20 @@ class uniRequest {
|
||||
});
|
||||
}
|
||||
|
||||
private handleResponse(response: any,options:RequestOptions): any {
|
||||
if (options.interceptor?.response){
|
||||
private handleResponse(response: any, options: RequestOptions): any {
|
||||
if (options.interceptor?.response) {
|
||||
response = options.interceptor?.response(response);
|
||||
}else if (this.interceptors?.response) {
|
||||
} else if (this.interceptors?.response) {
|
||||
response = this.interceptors?.response(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 {
|
||||
throw error;
|
||||
}
|
||||
@ -122,6 +150,23 @@ class uniRequest {
|
||||
options.method = "GET";
|
||||
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 {
|
||||
if (options.params && Object.keys(options.params).length > 0) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
</view>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup >
|
||||
import { ref, getCurrentInstance } from "vue";
|
||||
import {login,getInfo} from "@/http/apis";
|
||||
@ -17,7 +16,6 @@ code:data.detail.code
|
||||
})
|
||||
if (res.code===200){
|
||||
uni.setStorageSync('token',res.data.token);
|
||||
console.log(uni.getStorageSync('token'),'11111')
|
||||
getUserInfo()
|
||||
}
|
||||
}
|
||||
@ -31,7 +29,6 @@ const res=await getInfo()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.main {
|
||||
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=""/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wrap1">
|
||||
<div class="wrap1_1 verified">已核销</div>
|
||||
<div class="wrap1_2">
|
||||
@ -66,7 +65,6 @@
|
||||
<script setup>
|
||||
import {ref} from 'vue'
|
||||
import {onShow} from "@dcloudio/uni-app";
|
||||
|
||||
const modeClass = ref('')
|
||||
const show = ref(true)
|
||||
const userInfo = ref(uni.getStorageSync('userInfo') ?? {})
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="large-container">
|
||||
<div class="content1">
|
||||
<div class="wrap1">
|
||||
<image src="../../static/zy68.png"></image>
|
||||
<image :src="currentAvatar"></image>
|
||||
</div>
|
||||
<div class="wrap2">
|
||||
<div class="wrap2_1">恢复默认头像</div>
|
||||
@ -38,10 +38,35 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import {updateAvatar, upload} from "@/http/apis";
|
||||
import {nextTick, ref} from 'vue'
|
||||
const currentAvatar=ref('')
|
||||
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>
|
||||
<style scoped lang="scss">
|
||||
|
Loading…
Reference in New Issue
Block a user