Commit c0bff6a0 authored by 郝聪敏's avatar 郝聪敏

新增wepy request工具函数

parent d6de1426
......@@ -998,6 +998,11 @@
"resolved": "http://npmprivate.quantgroups.com/@wepy%2fcore/-/core-2.0.0-alpha.16.tgz",
"integrity": "sha512-kIUlfmGwsOtKFEFxzmxGFyVL6CWojT9LWHQOTKQ6X+oRLGuUbSe6yYckLt2ZAu2Pg19J65OeSIie5hToicJO5Q=="
},
"@wepy/use-promisify": {
"version": "2.0.6",
"resolved": "http://npmprivate.quantgroups.com/@wepy%2fuse-promisify/-/use-promisify-2.0.6.tgz",
"integrity": "sha512-iZt4j1KU3YzNB5ilv5GS8kv0tqoLFtnAgcg6HDAmJ5Reol+imLsRENUxMdsfpO6oOxck4SSTzgSLOx3ccnC/qQ=="
},
"@wepy/x": {
"version": "2.0.4",
"resolved": "http://npmprivate.quantgroups.com/@wepy%2fx/-/x-2.0.4.tgz",
......
......@@ -18,6 +18,7 @@
"license": "MIT",
"dependencies": {
"@wepy/core": "^2.0.0-alpha.16",
"@wepy/use-promisify": "^2.0.6",
"@wepy/x": "^2.0.2"
},
"devDependencies": {
......
......@@ -8,8 +8,12 @@
</style>
<script>
import wepy from '@wepy/core';
import http from './common/wxRequest';
import vuex from '@wepy/x';
import promisify from '@wepy/use-promisify';
import { login } from './common/api';
wepy.use(promisify);
wepy.use(vuex);
wepy.app({
......@@ -20,50 +24,47 @@ wepy.app({
globalData: {
statusBarHeight: ''
},
onLaunch() {
async onLaunch() {
let that = this;
wx.getSystemInfo({
success: function (res) {
that.$options.globalData.statusBarHeight = res.statusBarHeight;
}
});
wx.setStorageSync('onNetworkStatusChange', true);
if (!wx.getStorageSync('openId')) {
wx.login({
success (res) {
if (res.code) {
// 发起网络请求,告诉后端
http.post('/');
wx.setStorageSync('wxCode', res.code);
} else {
console.log('登录失败!' + res.errMsg);
}
}
});
}
wx.checkSession({
success () {
console.log('已登录');
// session_key 未过期,并且在本生命周期一直有效
},
fail () {
// session_key 已经失效,需要重新执行登录流程
wx.login({
success (res) {
if (res.code) {
// 发起网络请求,告诉后端
wx.setStorageSync('wxCode', res.code);
} else {
console.log('登录失败!' + res.errMsg);
}
}
});
const { code } = await wepy.wx.login();
const userInfo = await login(code);
wx.setStorageSync('openId', userInfo.openId);
wx.setStorageSync('isRegister', userInfo.isRegister);
}
});
wx.setStorageSync('onNetworkStatusChange', true);
// wx.checkSession({
// success () {
// console.log('已登录');
// // session_key 未过期,并且在本生命周期一直有效
// },
// fail () {
// // session_key 已经失效,需要重新执行登录流程
// wx.login({
// success (res) {
// if (res.code) {
// // 发起网络请求,告诉后端
// wx.setStorageSync('wxCode', res.code);
// } else {
// console.log('登录失败!' + res.errMsg);
// }
// }
// });
// }
// });
wx.onNetworkStatusChange((res) => {
console.log('onNetworkStatusChange', res.isConnected);
wx.setStorageSync('onNetworkStatusChange', res.isConnected);
});
},
onError(e) {
console.log('onError', e);
},
methods: {}
});
</script>
......
import http from './wxRequest';
module.exports = {
login() {
return http.post();
login(code) {
return http.post(`/api/user/login?code=1235`);
},
register(params) {
return http.post('/api/user/register', params, { 'content-type': 'application/json' });
},
getUserInfo(params) {
return http.post('/api/user/main', params);
},
getAwardsInfo(params) {
return http.post('/api/prize/list', params);
},
getAwardsDetail(params) {
return http.post('/api/prize/batch', params);
},
getActivityFeed(params) {
return http.post('/api/activity/feed', params);
},
addGold(params) {
return http.post('/api/user/book', params);
},
signIn(params) {
return http.post('/api/user/signin', params, { 'content-type': 'application/json' });
},
getPrizeList(params) {
return http.post('/api/prize/list', params, { 'content-type': 'application/json' });
}
};
import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify';
const baseUrl = 'localhost:8000';
const baseUrl = 'https://luckiiapi.q-gp.com/yapi/mock/325';
const request = (url, options) => {
const request = async (url, options) => {
const defaultOptions = {
method: 'post',
header: { 'content-type': 'applicction/x-www-form-urlencoded' }
......@@ -11,6 +12,7 @@ const request = (url, options) => {
url = baseUrl + url;
const isConnected = wx.getStorageSync('onNetworkStatusChange');
console.log('isConnected', isConnected);
if (!isConnected) {
wx.showToast({
title: '无网络',
......@@ -20,26 +22,21 @@ const request = (url, options) => {
return;
}
const promise = new Promise((resolve, reject) => {
/*wepy.request({
return wepy.wx.request({
url: url,
data: options.data,
method: options.method,
header: options.header,
success: res => {
if (res.statusCode == 200) {
if (res.data.code == '2000') {
resolve(res.data.data);
header: options.header
}).then(res => {
if (res.statusCode === 200) {
if (res.data.code === 2000) {
return res.data.data;
}
}
reject(res);
},
fail: res => {
reject(res);
}
});*/
Notify({ message: res.data.detail || '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true });
}).catch(res => {
Notify({ message: '请求失败,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true });
});
return promise;
};
const post = (url, data, header) => {
......
......@@ -6,18 +6,6 @@
<div class="gift" @tap="click"></div>
</div>
<div class="chest-open" :class="{'show': show, 'blur': blur}">
<!-- <div class="mod-chest-cont">
<div class="content">
<div>您可真幸运~</div>
<image class="gift-image" src="/static/images/peo2.jpg"></image>
<div>时尚卡通水杯</div>
</div>
<div class="func">
<button class="chest-btn" @tap="go">再去挑战</button>
<button class="chest-btn" @tap="go">查看</button>
</div>
</div> -->
<div class="dialog" :class="{'fail-dialog': !isWin}">
<div class="star">
<image class="star-image" src="/static/images/star@2x.png"></image>
......@@ -35,8 +23,8 @@
</div>
<div class="success-content" v-if="isWin">
<div class="des">恭喜您中奖!</div>
<image class="image" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590418868788&di=5f7d14c51ea4d224c68d2f84b528c6f0&imgtype=0&src=http%3A%2F%2Fimg2.imgtn.bdimg.com%2Fit%2Fu%3D2413142997%2C2945797382%26fm%3D214%26gp%3D0.jpg"></image>
<div class="name">勃垦地进口红酒精装版</div>
<image class="image" :src="joinRecord.prize.photoUrl"></image>
<div class="name">{{joinRecord.prize.name}}</div>
</div>
<div class="dialog-footer">
<button class="btn" @tap="go">立即查看</button>
......@@ -52,7 +40,12 @@
wepy.component({
props: {
isWin: false
joinRecord: {
type: Object,
default() {
return {};
}
}
},
data: {
showAnimation: true,
......@@ -62,6 +55,13 @@
blur: false,
opened: false
},
computed: {
isWin() {
console.log('this.joinRecord.status.value', this.joinRecord);
if (!this.joinRecord.id) return false;
return +this.joinRecord.status.value === 3;
}
},
methods: {
click: function() {
this.shake = true;
......@@ -98,7 +98,7 @@
created() {
// setTimeout(() => {
this.showAnimation = true;
this.click();
// this.click();
// }, 1000);
}
});
......
......@@ -20,15 +20,14 @@
<div class="content">
<div class="des">恭喜您!</div>
<image class="image" src="/static/images/gold@2x.png"></image>
<div class="info">通过邀请以下好友,您获得15克币</div>
<div class="user">
<image class="user-img" src="/static/images/test1.jpg"></image>
<image class="user-img" src="/static/images/test1.jpg"></image>
<image class="user-img" src="/static/images/test1.jpg"></image>
<div class="info">通过邀请以下好友,您获得{{goldNum}}克币</div>
<div class="user" :class="{'one-user': inviteinfo.length === 1 }">
<image class="user-img" v-for="item in users" :src="item.avatarUrl"></image>
<span class="user-rest" v-if="inviteinfo.length > 3">...</span>
</div>
</div>
<div class="dialog-footer">
<button class="btn" @tap="go">立即领取</button>
<button class="btn" @tap="getGold">立即领取</button>
</div>
</div>
</div>
......@@ -38,39 +37,34 @@
wepy.component({
props: {
showMenus: {
type: Boolean,
default: false
inviteinfo: {
type: Array
}
},
data: {
menus: [
{ img: '/static/images/awards@2x.png', title: '我的抽奖', path: '/pages/awards' },
{ img: '/static/images/feedback@2x.png', title: '规则与帮助', path: '/pages/feedback' },
{ img: '/static/images/help@2x.png', title: '问题反馈', path: '/pages/help' }
],
show: false,
popupStyle: ''
computed: {
goldNum() {
return this.inviteinfo.reduce((p, n) => {
p += +n.quantity;
return p;
}, 0);
},
watch: {
showMenus(v) {
if (!v) {
setTimeout(() => {
this.show = false;
}, 300);
} else {
this.show = true;
}
}
users() {
return this.inviteinfo.slice(0, 3);
},
computed: {
hide() {
return !this.showMenus;
ids() {
return this.inviteinfo.reduce((p, n) => {
p.push(n.accountItemId);
return p;
}, []);
}
},
methods: {
getAwards: function() {
this.show = false;
getGold: function() {
this.$emit('getSharedGold', {
openid: wx.getStorageSync('openId'),
itemIdList: this.ids.join(','),
quantity: this.goldNum
});
}
}
});
......@@ -250,13 +244,15 @@
height: 50rpx;
border-radius: 50%;
}
&:after {
content: '...';
.user-rest {
position: absolute;
bottom: -5rpx;
bottom: 11rpx;
right: -46rpx;
}
}
.one-user {
justify-content: center;
}
}
.dialog-footer {
display: flex;
......
<template>
<div style="{{containerStyle}}" class="icon-container">
<star-animation v-if='flyAnimation'></star-animation>
<star-animation v-if="flyAnimation"></star-animation>
<div class="sign" v-if="type === 'sign'" @tap="signIn">
<image class="sign-in" :src="signNotCompletedUrl" v-if="!signComplete" :class="{'jump': !sign, 'fly': sign}" ></image>
<image class="sign-comlete" :src="signCompletedUrl" v-if="sign"></image>
......@@ -11,7 +11,7 @@
<div v-if="type === 'gold'" class="gold">
<div class="add-gold" v-if="addGold">
<image class="add-gold-image" :src="addGoldUrl"></image>
<span class="add-gold-num">+10</span>
<span class="add-gold-num">+{{addGoldNum}}</span>
</div>
<div class="show-gold" @tap="showAnimation">
<div class="sunshine" v-if="addsunshine"></div>
......@@ -57,27 +57,29 @@
data: {
showAnimation: false,
addGold: false,
addGoldNum: 0,
addCount: 0,
addsunshine: false,
signComplete: false,
signComplete: true,
signNotCompletedUrl: '/static/images/sign@2x.png',
signCompletedUrl: '/static/images/sign-completed@2x-70_70px.png',
shareUrl: '/static/images/share@2x.png',
lotteryUrl: '/static/images/lottery@2x.png',
containerStyle: '',
flyAnimation: false
flyAnimation: false,
isFirst: true
},
props: {
title: '',
sign: {
type: Boolean,
default: false
default: true
},
gold: {
type: Boolean,
default: false
default: true
},
des: {
type: String | Number,
default: ''
},
type: {
......@@ -117,27 +119,38 @@
}
},
watch: {
des(newVal, oldVal) {
if (this.type === 'gold') {
if (!this.addCount) {
this.addCount ++;
return;
}
this.addGold = true;
this.addGoldNum = newVal - oldVal;
this.addCount ++;
}
},
gold(v) {
if (!v) {
this.addsunshine = false;
timeout1 = null;
} else {
timeout1 = setTimeout(() => {
if (this.isFirst) {
this.isFirst = false;
return;
}
setTimeout(() => {
this.addsunshine = true;
}, 1500);
}
},
sign(v) {
if (this.isFirst) {
this.signComplete = false;
this.flyAnimation = false;
console.log(v, this.signComplete);
if (!v) {
timeout = null;
} else {
timeout = setTimeout(() => {
this.addsunshine = false;
this.isFirst = false;
return;
}
if (v) {
setTimeout(() => {
this.signComplete = true;
this.flyAnimation = true;
console.log('signComplete');
}, 1100);
}
}
......@@ -148,7 +161,8 @@
[this.bgColor, this.fontColor] = [this.fontColor, this.bgColor];
},
signIn: function() {
this.$emit('sign-in', !this.sign);
if (this.sign) return;
this.$emit('sign-in', true);
},
showAnimation: function() {
this.addGold = !this.addGold;
......
......@@ -84,14 +84,14 @@
</video> < !-->
<view class="rightcont">
<view class="info">奖品库存: 1/8</view>
<view class="info">中奖概率: {{item.id}}/3000</view>
<view class="info">中奖概率: {{userAccount}}/3000</view>
<view class="progress">
<view class="text">{{progress}}%</view>
<view class="orange" style="{{progressStyle}}"></view>
</view>
</view>
<!-- <video-loading v-if="item.time === 0"/> -->
<image class="images" :src="item.url" mode="widthFix"></image>
<image class="images" :src="item.photoUrl" mode="widthFix"></image>
</view>
</swiper-item>
</swiper>
......@@ -116,6 +116,10 @@
total: {
type: Number,
value: 0
},
userAccount: {
type: Number,
value: 0
}
},
data: {
......
This diff is collapsed.
......@@ -2,9 +2,7 @@ import Vuex from '@wepy/x';
export default new Vuex.Store({
state: {
userInfo: {
avatarUrl: '/static/images/user@2x.png'
},
userInfo: '',
isConnected: true
},
mutations: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment