add global interceptor for all request
This commit is contained in:
parent
1b39bb3f9c
commit
f13017fa7c
@ -1,5 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
require('api/request');
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
mpType: 'app',
|
mpType: 'app',
|
||||||
onLaunch() {
|
onLaunch() {
|
||||||
|
30
src/api/game.ts
Normal file
30
src/api/game.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
export const searchGames = (params: any) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.request({
|
||||||
|
url: 'request/games',
|
||||||
|
success: (res) => {
|
||||||
|
resolve && resolve(res.data);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject && reject(err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const checkWord = (params: any) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.request({
|
||||||
|
url: '/check_local/' + encodeURIComponent(params.word),
|
||||||
|
success: (res) => {
|
||||||
|
resolve && resolve(res.data);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject && reject(err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
24
src/api/request.ts
Normal file
24
src/api/request.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const host_base = 'https://dirty.kingsome.cn'
|
||||||
|
|
||||||
|
uni.addInterceptor('request', {
|
||||||
|
invoke(args) {
|
||||||
|
// request 触发前拼接 url
|
||||||
|
args.url = host_base + args.url
|
||||||
|
if (false) {
|
||||||
|
args.header = {
|
||||||
|
...args.header,
|
||||||
|
token: 'xxx'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success(args) {
|
||||||
|
// 请求成功后,修改code值为1
|
||||||
|
args.data.code = 1
|
||||||
|
},
|
||||||
|
fail(err) {
|
||||||
|
console.log('interceptor-fail',err)
|
||||||
|
},
|
||||||
|
complete(res) {
|
||||||
|
console.log('interceptor-complete',res)
|
||||||
|
}
|
||||||
|
})
|
@ -2,7 +2,7 @@
|
|||||||
<uni-card mode="style" @click="onClick(gData.gameId)">
|
<uni-card mode="style" @click="onClick(gData.gameId)">
|
||||||
<template v-slot:cover>
|
<template v-slot:cover>
|
||||||
<view class="custom-cover" @click="onClick(gData.gameId)">
|
<view class="custom-cover" @click="onClick(gData.gameId)">
|
||||||
<image class="cover-image" mode="aspectFill" :src="gData.cover">
|
<image class="cover-image" mode="aspectFill" :src="gData.banner">
|
||||||
</image>
|
</image>
|
||||||
<view class="cover-tag">
|
<view class="cover-tag">
|
||||||
<text class="uni-subtitle uni-white">20%折扣</text>
|
<text class="uni-subtitle uni-white">20%折扣</text>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="s-game-cell">
|
<view class="s-game-cell">
|
||||||
<view class="left-part">
|
<view class="left-part">
|
||||||
<img src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg">
|
<image
|
||||||
|
src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg"
|
||||||
|
mode="aspectFit"
|
||||||
|
></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="right-part">
|
<view class="right-part">
|
||||||
<view class="title-view">
|
<view class="title-view">
|
||||||
@ -14,8 +17,8 @@
|
|||||||
<uni-tag v-for="tag in tagList" :text="tag" inverted="true" type="error"></uni-tag>
|
<uni-tag v-for="tag in tagList" :text="tag" inverted="true" type="error"></uni-tag>
|
||||||
</view>
|
</view>
|
||||||
<view class="price-view">
|
<view class="price-view">
|
||||||
<view>游戏英文名</view>
|
<view class="price">¥100</view>
|
||||||
<view class="price">100</view>
|
<view>¥150(日本)</view>
|
||||||
<uni-tag text="25%折扣" type="error"></uni-tag>
|
<uni-tag text="25%折扣" type="error"></uni-tag>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -45,12 +48,14 @@ export default class extends Vue{
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
uni-image{
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
.left-part{
|
.left-part{
|
||||||
width: 25%;
|
width: 25%;
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
.left-part img{
|
|
||||||
max-width: 150px;
|
|
||||||
}
|
|
||||||
.right-part {
|
.right-part {
|
||||||
width: 75%;
|
width: 75%;
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
|
@ -2,5 +2,13 @@ export interface IGameInfo{
|
|||||||
gameId: string
|
gameId: string
|
||||||
name: string
|
name: string
|
||||||
ename: string
|
ename: string
|
||||||
cover: string
|
platform?: number
|
||||||
|
tags?: string[]
|
||||||
|
icon?: string
|
||||||
|
banner?: string
|
||||||
|
price?: number
|
||||||
|
originPrice?: number,
|
||||||
|
priceCountry?: string,
|
||||||
|
discountLeftTime?: string,
|
||||||
|
cutOff?: number
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import BigImgCell from '@/components/BigImgCell/index.vue'
|
import BigImgCell from '@/components/BigImgCell/index.vue'
|
||||||
import { IGameInfo } from '@/modules/gameinfo'
|
import { IGameInfo } from '@/modules/gameinfo'
|
||||||
|
import { checkWord } from '@/api/game'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'Index',
|
name: 'Index',
|
||||||
@ -25,10 +26,17 @@ export default class extends Vue{
|
|||||||
private games: IGameInfo[] = []
|
private games: IGameInfo[] = []
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
checkWord({word: '毛岸英'})
|
||||||
|
.then(res => {
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
this.games.push({
|
this.games.push({
|
||||||
gameId: i + '',
|
gameId: i + '',
|
||||||
cover: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
|
banner: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
|
||||||
name: '测试游戏' + i,
|
name: '测试游戏' + i,
|
||||||
ename: 'test game ' + i
|
ename: 'test game ' + i
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user