This commit is contained in:
zpc 2025-05-13 23:29:19 +08:00
parent 09b93532f1
commit 440ec76188
7 changed files with 353 additions and 17 deletions

View File

@ -10,7 +10,7 @@ export default {
},
onLaunch: function (options) {
// console.log("App Launch", options, window.location.href);
// #ifdef MP-WEIXIN
const updateManager = uni.getUpdateManager();

View File

@ -1,7 +1,7 @@
import MiniProgramPlatform from './MiniProgramPlatform';
import AppPlatform from './AppPlatform';
import H5Platform from './H5Platform';
import WebAppPlatform from './WebAppPlatform';
class PlatformFactory {
static create() {
// 判断小程序环境
@ -15,6 +15,28 @@ class PlatformFactory {
//#endif
// 判断 H5 环境
//#ifdef WEB
// if(window.location.href.includes('cb2039d0e35094521ae46a1d11b0ddd1')){
// return new WebAppPlatform();
// }
console.log(window.location.href);
//window.location.search
let is_web_app = uni.getStorageSync('is_web_app');
let search = window.location.search;
if (search != null && search != '') {
const searchParams = new URLSearchParams(window.location.search);
const code = searchParams.get('_p');
if (code && code == 'cb2039d0e35094521ae46a1d11b0ddd1') {
uni.setStorageSync('is_web_app', true);
is_web_app = true;
}
}
if (uni.getStorageSync('is_web_app') != null && uni.getStorageSync('is_web_app') != '') {
is_web_app = true;
}
if (is_web_app) {
return new WebAppPlatform();
}
return new H5Platform();
//#endif

View File

@ -0,0 +1,82 @@
import BasePlatform from './BasePlatform';
import H5Platform from './H5Platform';
function parseQueryString(queryString) {
// 如果以 ? 开头,先去掉 ?
if (queryString.startsWith('?')) {
queryString = queryString.substring(1);
}
const params = {};
const pairs = queryString.split('&');
for (const pair of pairs) {
const [key, value] = pair.split('=');
// 解码 URI 组件
params[key] = decodeURIComponent(value);
}
return params;
}
class WebAppPlatform extends H5Platform {
constructor() {
super();
this.code = 'WEB_APP';
this.env = 'WEB_APP';
}
share({ title, desc, image, url }) {
console.log(`H5分享${title} - ${desc}`);
// 调用浏览器原生分享(如果可用)
if (navigator.share) {
return navigator.share({ title, text: desc, url });
}
// 降级方案
alert(`请手动分享:${url}`);
}
downloadFile(url) {
return new Promise((resolve, reject) => {
try {
// 创建一个隐藏的a标签
const a = document.createElement('a');
a.href = url;
a.download = url.split('/').pop() || 'download'; // 使用URL中的文件名或默认名称
a.style.display = 'none';
document.body.appendChild(a);
a.click(); // 触发下载
document.body.removeChild(a); // 清理DOM
resolve({ success: true });
} catch (error) {
console.error('下载失败:', error);
// 降级方案,直接打开
window.location.href = url;
resolve({ success: false, error: error.message });
}
});
}
/**
* 重写获取用户中心菜单列表添加微信小程序特有菜单
* @returns {Array} 菜单项数组
*/
getUserMenuList() {
// 获取基础菜单列表
const baseMenuList = super.getUserMenuList();
// 添加客服菜单项(仅微信小程序)
const customServiceMenu = {
id: 10,
show: true,
title: '关于',
icon: 'my/about.png',
path: '/pages/other/about',
handler: this.navigateToPath.bind(this)
};
// 将客服菜单插入到第二个位置
return [...baseMenuList.slice(0, baseMenuList.length-1), customServiceMenu, ...baseMenuList.slice(baseMenuList.length-1)];
}
}
export default WebAppPlatform;

View File

@ -383,6 +383,12 @@
"style": {
"navigationStyle": "custom"
}
},
{
"path" : "pages/other/about",
"style": {
"navigationStyle": "custom"
}
}
],
"subPackages": [{

31
pages/other/about.vue Normal file
View File

@ -0,0 +1,31 @@
<template>
<page-container title="关于" :showBack="true">
<!-- https://image.zfunbox.cn/icon_108.png -->
</page-container>
</template>
<script>
import PageContainer from '@/components/page-container/page-container.vue'
export default {
components: {
PageContainer
},
data() {
return {}
},
onLoad() {
this.load();
},
methods: {
async load() {
},
}
}
</script>
<style lang="scss">
</style>

View File

@ -34,8 +34,9 @@
<image :src="$img1('my/ic_alipay.png')" style="width: 320rpx; height: 96rpx;" mode=""></image>
</view>
<view class="center" style="width: 686rpx; height: 92rpx; margin: 46rpx auto 0; background-color: #333333; border-radius: 16rpx;" @click="pay">
<text style="color: #CDEF27; font-size: 24rpx;">确认支付</text>
<view class="center" style="width: 686rpx; height: 92rpx; margin: 46rpx auto 0; background-color: #333333; border-radius: 16rpx;" @click="pay"
:class="{'btn-active': isPaying}">
<text style="color: #CDEF27; font-size: 24rpx;">{{isPaying ? '支付中...' : '确认支付'}}</text>
</view>
@ -54,6 +55,7 @@ import {getDiamondList,createOrderProducts,getDiamondOrderLog} from '@/common/se
money:0
},
order_num:"",
isPaying: false,
}
},
onLoad(options){
@ -91,14 +93,24 @@ import {getDiamondList,createOrderProducts,getDiamondOrderLog} from '@/common/se
* 支付
*/
async pay(){
let pro= this.dataList[this.currentIndex];
console.log(pro);
const res= await createOrderProducts(pro.products_id);
console.log(res);
this.order_num= res.order_num;
const status = await this.$platform.pay({ data: res.res });
if (status == 'success') {
this.getPrizeLog(res.order_num);
if(this.isPaying) {
return;
}
try {
this.isPaying = true;
let pro= this.dataList[this.currentIndex];
console.log(pro);
const res= await createOrderProducts(pro.products_id);
console.log(res);
this.order_num= res.order_num;
const status = await this.$platform.pay({ data: res.res });
if (status == 'success') {
this.getPrizeLog(res.order_num);
}
} catch(e) {
console.error(e);
} finally {
this.isPaying = false;
}
},
/**
@ -165,4 +177,9 @@ import {getDiamondList,createOrderProducts,getDiamondOrderLog} from '@/common/se
}
.btn-active {
opacity: 0.8;
transform: scale(0.98);
}
</style>

View File

@ -36,7 +36,7 @@
<view>奖励总额</view>
<view class="money">
{{ commission }}
<text></text>
<text></text>
</view>
</view>
<view class="icon">
@ -47,11 +47,19 @@
</view>
<!-- 添加我的邀请码展示区域 -->
<view class="my-invite-code" v-if="userInfo.uid">
<view class="invite-code-title">我的邀请码</view>
<view class="invite-code-value" @click="copyMyInviteCode">{{ userInfo.uid }}</view>
</view>
<!-- // -->
<view class="" style="flex-direction: row; display: flex; width: 686rpx; margin: 40rpx auto;">
<button v-if="!ish5" open-type="share" class="invite-btn">立即邀请</button>
<button v-if="ish5" class="invite-btn" @click="yaoaing()">立即邀请</button>
<button class="invite-btn2" style="margin-left: 20rpx;" @click="showPosterPopup">生成海报</button>
<button v-if="!isApp" class="invite-btn2" style="margin-left: 20rpx;" @click="showPosterPopup">生成海报</button>
<button v-if="isApp && !hasBoundCode" class="invite-btn2" style="margin-left: 20rpx;" @click="showBindCodePopup">绑定邀请码</button>
<button v-if="isApp && hasBoundCode" class="invite-btn2 " style="margin-left: 20rpx;">已绑定邀请码</button>
</view>
<view class="invite-log">
@ -74,7 +82,6 @@
<text class="title">{{ item.addtime }}</text>
</view>
<view class="info-bd column">
<!-- <text>2024年3月18日 23:56</text> -->
<text class="money">消费{{ item.commission_money }}</text>
</view>
</view>
@ -93,11 +100,24 @@
:src="getXiaZai()"></image>
</view>
</uni-popup>
<uni-popup ref="bindCodePopup" type="center">
<view class="bind-code-popup">
<view class="bind-code-title">绑定邀请码</view>
<view class="bind-code-content">
<input type="text" v-model="inviteCode" placeholder="请输入邀请码" class="bind-code-input" />
<view class="bind-code-tips" v-if="hasBoundCode">您已绑定邀请码不可更改</view>
</view>
<view class="bind-code-btns">
<button class="bind-code-cancel" @click="closeBindCodePopup">取消</button>
<button class="bind-code-confirm" :disabled="hasBoundCode" @click="bindInviteCode">确定</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import { getUserInfo } from '@/common/server/user';
export default {
data() {
var isH5 = false;
@ -113,7 +133,11 @@ export default {
total: 0,
ish5: isH5,
logo_image: '',
commission: 0
commission: 0,
isApp: false,
inviteCode: '',
hasBoundCode: false,
userInfo: {}
}
},
onShareAppMessage() {
@ -128,6 +152,30 @@ export default {
},
onLoad() {
console.log(uni.getStorageSync('userinfo').ID)
console.log(this.$platform.code);
if (this.$platform.code == 'WEB_APP') {
this.isApp=true;
this.ish5=true;
}
if (this.$platform.code == 'WEB_H5') {
this.isApp = false;
this.ish5 = true;
}
var that = this;
getUserInfo().then(res => {
console.log(res);
that.userInfo = res;
if(res.pid!=0){
that.hasBoundCode = true;
}
// this.hasBoundCode = res.data.hasBound;
// if (this.hasBoundCode) {
// this.inviteCode = res.data.inviteCode || '';
// }
})
},
methods: {
yaoaing() {
@ -136,6 +184,12 @@ export default {
});
this.$c.msg("链接已复制,快去分享吧~")
},
copyMyInviteCode() {
uni.setClipboardData({
data: this.userInfo.ID + ''
});
this.$c.msg("邀请码已复制")
},
saveImageToPhotosAlbum() {
const imageUrl = this.logo_image; //
this.$platform.downloadFile(imageUrl).then(res => {
@ -191,6 +245,41 @@ export default {
showPosterPopup() {
this.$refs.posterPopup.open();
},
showBindCodePopup() {
//
console.log(this.userInfo );
if(this.userInfo.pid!=0){
this.$c.msg("您已绑定邀请码,不可更改");
return;
}
this.$refs.bindCodePopup.open();
},
closeBindCodePopup() {
this.$refs.bindCodePopup.close();
},
bindInviteCode() {
if (!this.inviteCode) {
this.$c.msg("请输入邀请码");
return;
}
let that = this;
that.req({
url: 'bind_invite_code',
data: {
invite_code: that.inviteCode
},
success(res) {
if (res.status === 1) {
that.$c.msg("绑定成功");
that.hasBoundCode = true;
that.closeBindCodePopup();
} else {
that.$c.msg(res.msg || "绑定失败,请重试");
}
}
})
}
}
}
@ -450,6 +539,12 @@ page {
color: #D8FD24;
font-size: 24rpx;
// background: url($imgurl+'my/promotion_poster.png') no-repeat 0 0 / 100% 100%;
&.disabled {
background-color: #666666;
color: #AAAAAA;
opacity: 0.8;
}
}
.invite-log {
@ -599,4 +694,87 @@ page {
height: 50rpx;
}
}
.bind-code-popup {
width: 600rpx;
background-color: #FFFFFF;
border-radius: 16rpx;
padding: 30rpx;
box-sizing: border-box;
.bind-code-title {
font-size: 32rpx;
color: #333333;
text-align: center;
font-weight: 500;
margin-bottom: 30rpx;
}
.bind-code-content {
margin-bottom: 40rpx;
.bind-code-input {
height: 80rpx;
background-color: #F5F5F5;
border-radius: 8rpx;
padding: 0 20rpx;
font-size: 28rpx;
color: #333333;
}
.bind-code-tips {
font-size: 24rpx;
color: #FF6B00;
margin-top: 16rpx;
}
}
.bind-code-btns {
display: flex;
justify-content: space-between;
button {
width: 240rpx;
height: 76rpx;
border-radius: 38rpx;
font-size: 28rpx;
}
.bind-code-cancel {
background-color: #F5F5F5;
color: #666666;
}
.bind-code-confirm {
background-color: #D8FD24;
color: #333333;
&:disabled {
opacity: 0.6;
}
}
}
}
.my-invite-code {
width: 686rpx;
margin: 20rpx auto 0;
background-color: #FFFFFF;
border-radius: 16rpx;
padding: 30rpx 0;
text-align: center;
.invite-code-title {
font-size: 28rpx;
color: #333333;
margin-bottom: 20rpx;
}
.invite-code-value {
font-size: 48rpx;
font-weight: bold;
color: #333333;
letter-spacing: 6rpx;
}
}
</style>