Commit 147e884d authored by mqf_0707's avatar mqf_0707

增加游戏原生混编功能

parent a2fa4918
No preview for this file type
export default {
hasGameModule: true, // 是否开启游戏模块自动注入dist
defaultPlugins: [
[
'@pluve/taro-plugin-mars', // taro暂时未支持阿里小程序自定义插件 需要引用插件的页面需配置
{
usingComponents: {// 原生组件引入
enable: true,
include: [ 'pages/index/index', 'pages/myPrize/myPrize' ]
}
}
]
],
addPages: ['pages/games/games'],// 游戏页面(自动注入app.json)
gamePages: [// 拷贝相关页面和依赖到dist目录
{ from: 'src/pages/games', to: 'dist/pages/games' },
{ from: 'minigame/node_modules', to: 'dist/node_modules'}
]
}
\ No newline at end of file
// eslint-disable-next-line import/no-commonjs
const path = require('path')
const { hasGameModule, defaultPlugins, addPages, gamePages } = require('./default').default
const config = {
projectName: 'taro-test',
......@@ -15,22 +16,16 @@ const config = {
alias: {
'@': path.resolve(__dirname, '..', 'src/')
},
plugins: [
[
'@pluve/taro-plugin-mars', // taro暂时未支持阿里小程序自定义插件 需要引用插件的页面需配置
plugins: hasGameModule ? [...defaultPlugins,[ // 是否开启原生页面自动注入
path.resolve(__dirname,'..')+'/plugin/changeAppJsonPlugin.js',
{
usingComponents: {
enable: true,
include: [ 'pages/index/index', 'pages/myPrize/myPrize' ]
}
addPages: addPages
}
]
],
]] : defaultPlugins,
defineConstants: {
},
copy: {
patterns: [
],
patterns: hasGameModule ? gamePages : [],
options: {
}
},
......
{
"pages":
[
"pages/index/index",
"pages/myPrize/myPrize",
"pages/browseGoods/browseGoods",
"pages/collectGoods/collectGoods",
"pages/orderGoods/orderGoods",
"pages/gamePage/gamePage"
],
"window":{
"enableSkia":"true",
"allowsBounceVertical":"NO",
"defaultTitle":"活动名称"
},
"plugins":{"cemMember":{"version":"*","provider":"3000000026642582"}}}
\ No newline at end of file
{
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"fyge-tbmini": {
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/fyge-tbmini/-/fyge-tbmini-1.4.8.tgz",
"integrity": "sha512-07+DySosT5rIR6nfkfqc1+hnfaeuiDrMGBe4dOVqi+IdWIbgjv/vY7Wm/zVQJ5gqjU607b2jfkzY/rA6r97s4A=="
}
}
}
{
"name": "",
"version": "1.0.0",
"main": "",
"license": "MIT",
"dependencies": {
"fyge-tbmini": "^1.3.1"
}
}
const fs = require('fs');
const path = require('path')
export default (ctx, options) => {
// plugin 主体
const { addPages = [] } = options
ctx.onBuildStart(() => {
// console.log('编译开始!')
})
ctx.onBuildFinish(() => {
const dirUrl = path.resolve(__dirname,'..')+'/dist/app.json'
const rawdata = fs.readFileSync(dirUrl);
const { pages, ...ext } = JSON.parse(rawdata);
let new_pages = [...pages,...addPages]
const new_info = {
pages: new_pages,
...ext
}
fs.writeFileSync(dirUrl, JSON.stringify(new_info));
console.log('文件写入成功!');
//ctx.writeFileToDist({ filePath: string, content: string })
})
}
\ No newline at end of file
......@@ -45,8 +45,7 @@ export default function RuleModal(props) {
}
// 助力条件为新会员
const res = await checkIsMember()
const isVip = res?.businessSuccess && res?.data?.isMember
const isVip = await checkIsMember()
// 已经是会员
if (isVip) {
......@@ -57,6 +56,10 @@ export default function RuleModal(props) {
}
}, 2000)
const closeMemberModal = () => {
// setMemberModalVisible(false)
}
return (
<View>
<Modal onClose={onClose} closePostion={closePostion} top={top}>
......@@ -71,7 +74,7 @@ export default function RuleModal(props) {
{
memberModalVisible &&
<member-modal
onClose={() => setMemberModalVisible(false)}
onClose={() => closeMemberModal()}
onAuthFail={onAuthFail}
onAuthSuccess={onAuthSuccess}
/>
......
......@@ -73,7 +73,7 @@ export default function GoodsPage(props) {
{
goodsList.map((item, i) => {
return (
<View className='goods-modal-container__content-item' key={item}>
<View className='goods-modal-container__content-item' key={'goods_'+i}>
<View className='goods-modal-container__content-item__img' onClick={() => goToGoodsDetail(item)}>
<Image mode='scaleToFill' src={item.image} />
</View>
......
export default {
env: 'test', // 云函数环境 test 测试环境 online 线上环境
requestType: 'yapi', // cloud: 云函数, yapi: yapi 接口, ams: ams接口,tornadoAPI: 风驰台接口
cloudName: 'CommonToC', // 主云函数项目名 CommonToC
requestType: 'tornadoAPI', // cloud: 云函数, yapi: yapi 接口, ams: ams接口,tornadoAPI: 风驰台接口
cloudName: 'luolai', // 主云函数项目名 CommonToC
sellerId: '2207644377875',
tornadoAPI: 'https://tornado.duibadev.com.cn/tbServer/api?db=xxx&proxyIp=xxx', // 新增:当requestType: 'tornadoAPI'时,找服务端提供地址
defaultActivityId: '5ff7e0a3e5c0d7dafd30dce5' // 默认活动id
tornadoAPI: 'https://tornado.duibadev.com.cn/tbServer/api?db=db3000000038851072&proxyIp=172.16.130.158', // 新增:当requestType: 'tornadoAPI'时,找服务端提供地址
defaultActivityId: '60642aafc752d118247c2a2d' // 默认活动id
}
.canvas {
width:100%;
height:100%;
}
.page-game {
width:100%;
height:100vh;
flex: 1;
display: flex;
flex-direction: column;
background: #f5cccd;
}
<view class="page-game">
<canvas id="canvas" type="2d" class="canvas" disable-scroll="true"
onTouchStart="onMouseEvent"
onTouchMove="onMouseEvent"
onTouchEnd="onMouseEvent"
onReady="onCanvasReady"
></canvas>
</view>
import { Main } from './output';
import { getUserAddress, favorShop, getAuthUserInfo, checkShopFavoredStatus, openDetail, reportAnalytics, commonToast, playBgMusic, getSystemInfo } from './utils';
//这种方式/表示client下面的路径
// import { getSystemInfo } from '/utils/utils';
//检查版本号
const checkSystem = async () => {
const { version } = await getSystemInfo();
console.log('version', version);
return versionCompare(version, '9.10.0');
}
//对比版本号
const versionCompare = (cur, compare) => {
const _cur = cur.split('.');
const _compare = compare.split('.');
if (+_cur[0] < +_compare[0]) {
return false;
} else if (+_cur[0] === +_compare[0] && +_cur[1] < +_compare[1]) {
return false;
} else if (+_cur[0] === +_compare[0] && +_cur[1] === +_compare[1] && +_cur[2] < +_compare[2]) {
return false;
}
return true;
}
/**
* 直接取,app
*/
const app = getApp()
/**
* 分享信息
*/
const SHARE_CONFIG = {//待写
title: 'babycare欢乐城!',
desc: '赢TF彩妆礼盒',
imageUrl: "https://yun.duiba.com.cn/db_games/activity/pacman/share.jpg",
path: 'pages/index/index'
}
Page({
//暂时先不用吧,有问题
data: {},
onLoad(query) {
// 页面加载
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
//带参数的取链接参数
if (query.inviteId) this.inviteId = query.inviteId;
//版本提示
checkSystem().then(r => {
if (!r) {
my.showToast({
content: "请升级最新版本的淘宝体验",
duration: 5000
});
}
});
},
onReady() {
},
onCanvasReady() {
console.log("进canvas了")
//版本检查
checkSystem().then(r => {
if (r) {//检查通过开始授权
this.getAuth();
}
});
},
//创建引入的Main
createMain() {
var self = this;
my.createCanvas({
id: 'canvas',
success: (ccc) => {
const dpr = my.getSystemInfoSync().pixelRatio
const windowWidth = my.getSystemInfoSync().windowWidth;
const windowHeight = my.getSystemInfoSync().windowHeight;
ccc.width = windowWidth * dpr + dpr;//重新修改会有误差
ccc.height = windowHeight * dpr + dpr;
// console.log(Main)
console.log(ccc.width, ccc.height)
if (!this.main) {
try {
this.main = new Main(ccc)
//添加事件,为了和main里的通信
this.main.addGlobalEvent("onMessage", self.onMessage, self)
} catch (err) {
console.error(err)
}
}
}
})
},
//授权
async getAuth() {
const userInfo = await getAuthUserInfo().catch(() => {
commonToast('未授权成功');
this.postMessage('mine.authorize', { success: false })
})
//未授权成功不进入活动
if (!userInfo) return
const { nickName, avatar } = userInfo
app.nickName = nickName;
app.avatar = avatar;
//检查是否关注的
const isFollow = await checkShopFavoredStatus(app.sellerId).catch(() => { })
app.isFollow = this.isFollow = isFollow;//app上也挂一个
//创建Main,授权登录完后才创建,也可定制在游戏内授权
this.createMain();
//分享图片,TODO,注释打开替换
const result1 = await app.cloud.file.getTempFileURL({ fileId: 'cloud://2D60DC04FC1888AF6F865B88F0B2EBCC//share.png' });
if (result1[0]) SHARE_CONFIG.imageUrl = result1[0].url
//音乐路径
const resultSrc = await app.cloud.file.getTempFileURL({ fileId: 'cloud://293F2E7D0C6799617660563A322DEE55//bgm_babycare.mp3' });
if (resultSrc[0]) this.musicUrl = resultSrc[0].url;
},
/**
* 获取及选择用户收货地址
* @param {*} prizeId
*/
async getUserAddress(prizeId) {
const userAddress = await getUserAddress().catch(res => {
commonToast(res.errorMessage)
this.postMessage('mine.getUserAddress', { success: false })
})
if (userAddress) {//格式需要修改具体
const { name, phone, address } = userAddress.duibaAddress
const { provinceName, cityName, countyName } = userAddress;
my.confirm({
title: '提示',
content: '确认使用该收货地址:' + name + phone + address,
confirmButtonText: '确定',
cancelButtonText: '取消',
success: (result) => {
const { confirm } = result
if (confirm) {
//发接口提交地址
const { cloud, activityId, cloudName } = app
cloud.function.invoke(cloudName, {//定制
activityId,
id: prizeId,
_id: prizeId,
// address,
name,
phone,
addressdetail: address,
provice: provinceName,
city: cityName,
area: countyName,
// address: JSON.stringify(userAddress.duibaAddress)
}, "receiveObjectPrize")
.then(res => {
if (res && res.success) {
//确认发送成功信息
this.postMessage('mine.getUserAddress', { success: true })
} else {
//新增失败0514
this.postMessage('mine.getUserAddress', { success: false })
}
})
.catch(() => {
//新增失败0514
this.postMessage('mine.getUserAddress', { success: false })
})
} else {
//新增失败0514
this.postMessage('mine.getUserAddress', { success: false })
}
},
})
}
},
/**
* 关注店铺
*/
async doFavorShop() {
const { sellerId } = getApp()
const success = await favorShop(sellerId).catch(err => {
// commonToast(err.errorMessage || '活动太火爆,请稍后重试')
//这个包括用户取消的,所以下面不用判断success了;
this.postMessage('mine.favorShop', { success: false })
// console.log("啊啊啊请问请问")
})
// console.log("asdasd",success)
if (success) {
this.postMessage('mine.favorShop', { success: true })
}
// else {
// // console.log("飒飒飒飒大苏打")
// this.postMessage('mine.favorShop', { success: false })
// }
},
//和main通信的方法,接收main的信息
onMessage(e) {
//接口名字
let netName = e.data.netName;
//接口参数
let parameter = e.data.parameter;
//暂时发现3个需要用户操作的接口
//定制的授权
if (netName == "mine.authorize") {
this.getAuth()
}
//获取地址
else if (netName == "mine.getUserAddress") {
this.getUserAddress(parameter.prizeId)
}
//关注店铺的操作
else if (netName == "mine.favorShop") {
this.doFavorShop()
}
//领养名字,有弹框的
else if (netName == "mine.getAdoptName") {
this.setData({ "adoptModalVisible": true, type: parameter.type })
}
//打开详情页,还有成功失败
else if (netName == "mine.openDetail") {
openDetail(parameter.itemId).then(
() => {
this.postMessage(netName, { success: true })
},
() => {
this.postMessage(netName, { success: false })
}
)
}
//前端同步接口
else if (netName.indexOf("mine") == 0) {
var data = { success: true }
switch (netName) {
case "mine.getAppData"://获取信息
data = {
success: true,
data: {
activityId: app.activityId,//|| "5e7c40e98564b57d7fb95812",
nickName: app.nickName,
avatar: app.avatar,
openId: app.openId,
inviteId: this.inviteId,//判断是否要发助力用
isFollow: app.isFollow
}
}
break;
case "mine.navigateToOutside"://跳转小程序外的页面
my.call("navigateToOutside", {
url: parameter.url
}, (res) => {
// my.alert({ content: "success - " + JSON.stringify(res)})
})
console.log(parameter.url)
break;
case "mine.navigateTo"://跳转小程序内的页面
my.navigateTo({
url: parameter.url
})
break;
case "mine.navigateBack"://返回页面
my.navigateBack({
delta: parameter.delta || 1
})
break;
case "mine.showSharePanel"://分享
//多一个参数
this.openId = parameter.openId;
my.showSharePanel()
break;
case "mine.reportAnalytics": ////淘宝自定义埋点
reportAnalytics(parameter.logkey);
break;
case "mine.openMusic": //音频
playBgMusic(parameter.isOn, this.musicUrl);
break;
case "mine.openRankPanel": //打开排行榜
this.setData({ "expRankModalVisible": true });
break;
}
this.postMessage(netName, data)
} else {
//获取后端接口
const { function: fc } = app.cloud;
//处理下带上activityId
if (!parameter) parameter = {};
parameter.activityId = app.activityId;
//netName得分割下
fc.invoke(netName.split(".")[0], parameter, netName.split(".")[1])
.then(res => {
// console.log("返回数据" + JSON.stringify(res));
//发送消息
this.postMessage(netName, res || { success: false })
}, (err) => {
//网络异常,返回失败
this.postMessage(netName, { success: false })
})
}
},
postMessage(netName, data) {
// this.main.dispatchGlobalEvent(netName, data)
this.main && this.main.dispatchGlobalEvent({ type: netName }, data)//以防复用事件event串了,就用这种方式
},
onShow() {
// 页面显示
this.main && this.main.run();
},
onHide() {
// 页面隐藏
this.main && this.main.pause();
},
onUnload() {
// 页面被关闭
this.main && this.main.destroy();
},
onTitleClick() {
// 标题被点击
},
onPullDownRefresh() {
// 页面被下拉
},
onReachBottom() {
// 页面被拉到底部
},
/**
* 分享参数处理
*/
onShareAppMessage() {
// 返回自定义分享信息
// const { activityId, openId } = app
// 发送分享记录,记录数据用
// API.getShareId({ activityId });
let { path, ...rest } = SHARE_CONFIG
if (this.openId) {
path = path + '?inviteId=' + this.openId
this.openId = null//用完清掉
}
console.log(path)
return {
...rest,
path
}
},
//鼠标事件
onMouseEvent(e) {
if (this.main) this.main.stage.onMouseEvent(e)
},
});
{
"disableScroll": "true"
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* 通用toast
* @param {string} content toast内容
* @param {number} duration 显示时长
*/
export const commonToast = (content, duration = 3000) => {
my.showToast({
content: content || '换个姿势再试一次~',
duration
});
};
/**
* 获取授权用户信息
* @returns {object} 用户登录信息
*/
export const getAuthUserInfo = () => {
return new Promise((resolve, reject) => {
my.authorize({
scopes: 'scope.userInfo',
success: res => {
my.getAuthUserInfo({
success: userInfo => { resolve(userInfo); }
});
},
fail: err => {
reject(err);
}
});
});
};
/**
* 获取系统信息
* @returns {object} 小程序系统信息
*/
export const getSystemInfo = () => {
return new Promise((resolve, reject) => {
my.getSystemInfo({
success: res => { resolve(res); },
fail: err => { reject(err); }
});
});
};
/**
* 执行关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export const favorShop = sellerId => {
return new Promise((resolve, reject) => {
my.tb.favorShop({
id: sellerId,
success: res => {
console.log(res, '关注店铺');
resolve(res);
},
fail: err => {
console.log(err, '关注店铺失败');
// error code 11 为用户取消操作不认作失败场景
// if (err.error !== 11) {
reject(err);
// }
}
});
})
};
/**
* 判断是否关注店铺
* @param {number} sellerId 店铺归属的卖家Id
* @returns {boolean} 关注状态
*/
export const checkShopFavoredStatus = sellerId => {
return new Promise((resolve, reject) => {
my.tb.checkShopFavoredStatus({
id: sellerId,
success: res => {
resolve(res.isFavor);
},
fail: err => {
reject(err);
}
});
});
};
/**
* 跳转到外部链接
* @param {string} url 跳转链接
*/
export const navigateToOutside = url => my.call("navigateToOutside", { url });
/**
* 跳转到内部链接(新开窗口)
* @param {string} url 跳转链接
*/
export const navigateTo = url => my.navigateTo({ url });
/**
* 跳转到内部链接(不新开窗口)
* @param {string} url 跳转链接
*/
export const redirectTo = url => my.redirectTo({ url });
/**
* 获取服务器时间
* @returns {number} 服务器时间戳
*/
export const getServerTime = () => {
return new Promise((resolve, reject) => {
my.getServerTime({
success: (res) => {
resolve(res.time);
},
fail: err => {
reject(err);
}
});
});
};
/**
* 收藏商品
* @param {number} 商品id
* @returns {object} 收藏结果
*/
export const collectGoods = id => {
return new Promise((resolve, reject) => {
my.tb.collectGoods({
id,
success: res => {
resolve(res);
},
fail: err => {
if (err.errorMessage === '该商品已收藏') {
// 已收藏没有给到errorCode,只能通过message判断
// 返回收藏成功,并且给到标记代表是已收藏的
resolve({ success: true, hasCollected: true, errorMessage: err.errorMessage });
} else if (err.error !== 11) {
// error code 11 为用户取消操作不认作失败场景
reject(err);
}
}
});
});
};
/**
* 查询商品收藏状态
* @param {number} 商品id
* @returns {boolean} 商品收场状态
*/
export const checkGoodsCollectedStatus = id => {
return new Promise((resolve) => {
my.tb.checkGoodsCollectedStatus({
id,
success: res => {
resolve(res.isCollect);
}
});
});
};
/**
* 时间格式化
* @param date 接收可以被new Date()方法转换的内容
* @param format 字符串,需要的格式例如:'yyyy-MM-dd hh:mm:ss'
* @returns {String}
*/
export const dateFormatter = (date, format = 'yyyy-MM-dd') => {
if (!date) return '-';
date = new Date(typeof date === 'string' && isNaN(date) ? date.replace(/-/g, '/') : date);
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'q+': Math.floor((date.getMonth() + 3) / 3),
'S': date.getMilliseconds()
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
}
}
return format;
};
/**
* 创建音频类
*/
class AudioModel {
constructor(opts = {}) {
const { src } = opts;
if (!src) {
console.error('请输入音频链接');
return false;
}
try {
const innerAudioContext = my.createInnerAudioContext();
Object.keys(opts).forEach(item => {
innerAudioContext[item] = opts[item];
});
return innerAudioContext;
} catch(e) {
console.error('当前版本不支持音频');
}
}
};
/**
* 创建音频实例
* @param {object} opts 配置对象 例 { src: '音频链接', autoplay: false }
*/
export const createAudio = opts => {
const audioInstance = new AudioModel(opts)
return audioInstance;
};
//暂时只有一个音乐,临时处理
let bgMusic
export const playBgMusic = (isOn,src) => {//待测试
if (isOn) {
if (!bgMusic) {
bgMusic = createAudio({
src: src||"https://yun.duiba.com.cn/db_games/activity/babycare_xiaoxiao/bgm_babycare.mp3",
autoplay: true,
loop: true//暂时无效?
});
//监听结束,因为loop无效
bgMusic.onEnded(() => {
// bgMusic.seek(0);
bgMusic.play();
})
console.log(src)
} else {
bgMusic.play();
}
} else {
if (bgMusic) {
// bgMusic.pause();
bgMusic.stop();
// bgMusic.seek(0);
}
}
}
/**
* 版本比较
* @param {string} cur 当前版本
* @param {string} compare 比较版本
*/
export const versionCompare = (cur, compare) => {
const _cur = cur.split('.');
const _compare = compare.split('.');
if (+_cur[0] < +_compare[0]) {
return false;
} else if ( +_cur[0] === +_compare[0] && +_cur[1] < +_compare[1] ) {
return false;
} else if (+_cur[0] === +_compare[0] && +_cur[1] === +_compare[1] && +_cur[2] < +_compare[2]) {
return false;
}
return true;
}
//暂时只有一个音乐,临时处理
// let bgMusic;
// let gameMusic;
let bgs = {
}
export const playBgMusic1 = (isOn, src) => {//待测试
for (let k in bgs) {
if (bgs[k].isOn) {
bgs[k].stop();
}
// bgs[k].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
const key = src;
if (isOn) {
if (!bgs[key]) {
bgs[key] = createAudio({
src: src,
autoplay: true,
loop: false /// TODO 暂时无效?2020.08.12 目前有效,但stop后还会跑数据,导致到音频结束到时间又自动播放
});
bgs[key].onPlay(() => {
bgs[key].isOn = true;
});
bgs[key].onStop(() => {
bgs[key].isOn = false;
});
/// TODO监听结束,因为loop无效 2020.08.12 loop有效,这个操作是为了解决stop之后还会跑音频数据的问题
bgs[key].onEnded(() => {
if (bgs[key].isOn) { // 判断自己记录的开关
bgs[key].play();
// bgs[key].isOn = true;
}
});
bgs[key].play(); // 安卓有时候autoplay好像莫得用
// console.log(src)
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
} else {
bgs[key].play();
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
} else {
if (bgs[key]) {
// bgs[key].pause(); /// pause 垃圾,不能用
bgs[key].stop();
// bgs[key].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
}
}
// TODO: 确认天猫是否也是9.3.0以下有问题
export const checkSystem = async ()=> {
const { version, app } = await getSystemInfo();
console.log('version', version);
return versionCompare(version, '9.3.0');
}
/**
* 获取淘宝用户收货地址
*/
export const getUserAddress = async (opts = {}) => {
let defaults = {
addAddress: 'show',
searchAddress: 'hide',
locateAddress: 'hide',
joinTag: '' // 分割收货地址符号(淘宝商家有特定发货需求)
};
const isValidVersion = await checkSystem();
if(!isValidVersion) {
commonToast('当前版本不支持选择收货地址,请升级到最新版本');
return;
}
let _opts = Object.assign({}, defaults, opts);
return new Promise((resolve, reject) => {
my.authorize({
scopes: 'scope.addressList',
success: () => {
const { addAddress, searchAddress, locateAddress, joinTag } = _opts;
if (!my.tb.chooseAddress) {
reject({ support: false, errorMessage: '当前版本不支持选择收货地址,请升级到最新版本' });
return false;
}
my.tb.chooseAddress({
addAddress,
searchAddress,
locateAddress
}, res => {
const { error, provinceName, countyName, cityName, streetName, detailInfo, name, telNumber } = res;
// 如果有error为用户取消操作不做操作
if (error) {
resolve(false);
} else {
resolve({
...res,
duibaAddress: {
name,
phone: telNumber,
address: [provinceName, cityName, countyName, streetName, detailInfo].join(joinTag)
}
});
}
}, res => {
reject(res);
})
},
});
});
};
/**
* 打开详情页
* @param {string} itemId
*/
export const openDetail = (itemId) => {
return new Promise((resolve, reject) => {
my.tb.openDetail({
itemId,
success: (res) => {
resolve(res)
},
fail: (res) => {
reject(res)
},
});
})
}
/**
* 自定义埋点的方法
* @param {string}} logkey
*/
export const reportAnalytics = (logkey) => {
my.reportAnalytics('click', {
// 标志某一类事件,方便数据分析进行分组
'logkey': logkey
})
}
\ No newline at end of file
import React, { useState } from 'react'
import { View } from '@tarojs/components'
import Taro, { useShareAppMessage, useDidShow } from '@tarojs/taro'
import classnames from 'classnames'
import { SHARE_CONFIG } from '@/const.js'
import { useLogin, useLoginFromShare } from '@/hooks/useLogin'
import { useActivityInfoModel, useLoginInfoModel } from '@/store'
......@@ -9,6 +10,8 @@ import RuleModal from '@/components/RuleModal/RuleModal'
import DoHelpModal from '@/components/DoHelpModal/DoHelpModal'
import TasksModal from '@/components/TasksModal/TasksModal'
import styles from './index.module.less'
import tbcc from 'tbcc-sdk-ts'
const { navigateTo } = tbcc.tb
const INDEX_CONFIG = {
bg: '', // 背景
......@@ -61,14 +64,21 @@ function Index() {
}
const onShare = () => my.showSharePanel()
const onGoMyPrizePage = () => Taro.navigateTo({ url: '/pages/myPrize/myPrize' })
const onGoMyPrizePage = () => navigateTo('/pages/myPrize/myPrize')
const homeStyle = classnames(styles.container,{
[`${styles['content_fixed']}`]: ruleModalVisible
})
return (
<View className={styles.container} style={{ backgroundImage: `url(${INDEX_CONFIG.bg})` }}>
<View className={homeStyle} style={{ backgroundImage: `url(${INDEX_CONFIG.bg})`}}>
<View className={styles.rule} style={{ backgroundImage: `url(${INDEX_CONFIG.ruleButton})` }} onTap={() => setRuleModalVisible(true)}>活动规则</View>
<View className={styles.my_prize} style={{ backgroundImage: `url(${INDEX_CONFIG.myPrizeButton})` }} onTap={onGoMyPrizePage}>我的奖品</View>
<View className={styles.share} style={{ backgroundImage: `url(${INDEX_CONFIG.shareButton})` }} onTap={onShare}>分享</View>
<View className={styles.tasks} style={{ backgroundImage: `url(${INDEX_CONFIG.taskButton})` }} onTap={() => setTasksModalVisible(true)}>任务</View>
<View className={styles.games} style={{ backgroundImage: `url(${INDEX_CONFIG.taskButton})` }} onTap={() => navigateTo('/pages/games/games')}>游戏</View>
<View className={styles['blank_content']}><text>{`dldlddddl\n212222222`}</text></View>
<View className={styles.bemember} onTap={() => setMemberVisible(true)}>入会</View>
{
......
......@@ -3,7 +3,9 @@
min-height: 100vh;
.image-property(cover, top center);
}
.content_fixed {
position: fixed;
}
.index_button() {
.wh(150px, 46px);
.border(#000);
......@@ -39,3 +41,13 @@
right: 20px;
top: 340px;
}
.games {
.index_button();
right: 20px;
top: 420px;
}
.blank_content {
width: 100%;
height: 2500px;
background: #eee;
}
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Image, ScrollView, View } from '@tarojs/components'
import API from '@/api'
import { DRAW_STATUS, PRIZE_TYPE } from '@/const'
......@@ -6,7 +6,6 @@ import DeliveryModal from '@/components/DeliveryModal/DeliveryModal'
import tbccTs from 'tbcc-sdk-ts'
import { useThrottle } from '@/hooks/useThrottle'
import { checkIsMember } from 'tbcc-sdk-ts/lib/utils'
import { useDidShow } from '@tarojs/taro'
import { dateFormatter } from '@/utils/date'
import './myPrize.less'
......@@ -56,13 +55,9 @@ function MyPrizeList() {
const [ memberVisible, setMemberVisible ] = useState(false)
const [ deliveryModalVisible, setDeliveryModalVisible ] = useState(false)
// useEffect(() => {
// fetchMyPriceList()
// }, [])
useDidShow(() => {
useEffect(() => {
fetchMyPriceList()
})
}, [])
async function fetchMyPriceList() {
const res = await getMyPrizeList()
......@@ -198,7 +193,7 @@ function MyPrizeList() {
<View className='my-prize-list'>
{myPrizeList.map((item, i) => {
return (
<View className='my-prize-item' key={item}>
<View className='my-prize-item' key={'prize_'+i}>
<Image className='my-prize-item__avatar' src={item.image} />
<View className='my-prize-item__content'>
......
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