This commit is contained in:
zpc 2025-05-21 20:11:42 +08:00
parent bbfd168c15
commit 1774490c54
12 changed files with 432 additions and 109 deletions

26
App.vue
View File

@ -11,31 +11,7 @@ export default {
onLaunch: function (options) {
// console.log("App Launch", options, window.location.href);
// #ifdef MP-WEIXIN
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
//
console.log(res.hasUpdate);
});
updateManager.onUpdateReady(function (res) {
uni.showModal({
title: "更新提示",
content: "新版本已经准备好,是否重启应用?",
success(res) {
if (res.confirm) {
// applyUpdate
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function (res) {
//
});
//#endif
var that = this;
this.$config.init().then(async (data) => {

View File

@ -41,7 +41,7 @@ const testing = {
// 根据环境变量选择对应配置
let currentEnv = production_wz;//production;//testing;//production_wz;
let currentEnv = testing;//production;//testing;//production_wz;
// 判断当前环境
// #ifdef H5

View File

@ -14,7 +14,6 @@ class H5Platform extends BasePlatform {
if (erudaInstance != null && erudaInstance != "") {
this.startDeb();
}
this.startDeb();
// eruda.init();
}
getPayData(url, data) {

View File

@ -0,0 +1,170 @@
import BasePlatform from './BasePlatform';
import {
parseQueryString
} from '@/common/util';
class IOSPlatform extends BasePlatform {
constructor() {
super();
this.code = 'IOS';
this.env = 'ios';
}
getPayData(url, data) {
data['quitUrl'] = escape(window.location.href);
data['returnUrl'] = escape(window.location.href);
console.log('处理数据', data);
return data;
}
pay({
data
}, event) {
console.log('支付1111');
return new Promise((resolve) => {
console.log(data);
// 检查是否已存在同ID的表单如果存在则先删除
const existingForm = document.getElementById('alipaysubmit');
if (existingForm) {
existingForm.parentNode.removeChild(existingForm);
}
// 创建一个临时div元素
const tempDiv = document.createElement('div');
// 将data作为HTML插入到div中假设data是表单的HTML字符串
tempDiv.innerHTML = data;
// 将表单添加到body中
document.body.appendChild(tempDiv.firstChild);
// 获取表单并提交
const form = document.getElementById('alipaysubmit');
if (form) {
form.submit();
resolve({
success: true
});
} else {
resolve({
success: false,
message: '表单创建失败'
});
}
});
}
share({
title,
desc,
image,
url
}) {
console.log(`H5分享${title} - ${desc}`);
// 调用浏览器原生分享(如果可用)
if (navigator.share) {
return navigator.share({
title,
text: desc,
url
});
}
// 降级方案
alert(`请手动分享:${url}`);
}
/**
* 选择地址
* @returns
*/
chooseAddress() {
return new Promise((resolve, reject) => {
uni.navigateTo({
url: '/pages/other/choose_address',
events: {
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
selectAddress: function(data) {
console.log(data, {
userName: data.address.receiver_name,
telNumber: data.address.receiver_phone,
detailed_address: data.address.detailed_address
})
resolve({
userName: data.address.receiver_name,
telNumber: data.address.receiver_phone,
detailed_address: data.address.detailed_address
});
},
someEvent: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('acceptDataFromOpenerPage', {
data: 'data from starter page'
})
}
})
});
}
downloadFile(url) {
return new Promise((resolve, reject) => {
resolve({
success: true
});
});
}
AppLaunch(options) {
console.log("AppLaunch", options);
}
getOrderNo(event) {
return new Promise((resolve, reject) => {
resolve(null);
});
}
/**
* 重写获取用户中心菜单列表处理H5特有的菜单需求
* @returns {Array} 菜单项数组
*/
getUserMenuList() {
// 获取基础菜单列表
const baseMenuList = super.getUserMenuList();
// H5环境下可能需要修改某些菜单项的行为
return baseMenuList.map(item => {
// 示例在H5环境下可能需要特殊处理某些菜单项
if (item.id === 6) { // 加入福利群菜单
return {
...item,
// 重新绑定处理函数可能需要增加H5特有的逻辑
handler: (menuItem, context) => {
this.handleJoinGroup(menuItem, context);
// 在H5环境下可能需要额外的处理比如尝试复制群号等
}
};
}
return item;
});
}
/**
* 开启调试
*/
startDeb() {
}
/**
* 关闭调试
*/
closeDeb() {
}
getVersion() {
return '1.0.0';
}
}
export default H5Platform;

View File

@ -1,7 +1,12 @@
import BasePlatform from './BasePlatform';
import RequestManager from '@/common/request.js'
import { sleep, parseQueryString } from '@/common/util.js'
import { getOrderStatus } from '@/common/server/order.js'
import {
sleep,
parseQueryString
} from '@/common/util.js'
import {
getOrderStatus
} from '@/common/server/order.js'
/**
* 小程序平台
*/
@ -17,7 +22,9 @@ class MiniProgramPlatform extends BasePlatform {
if (this.config) {
return this.config;
}
this.config = { isWebPay: true };
this.config = {
isWebPay: true
};
return this.config;
}
getPayData(url, data) {
@ -49,19 +56,21 @@ class MiniProgramPlatform extends BasePlatform {
let respay = await RequestManager.post(url, payPostData, false);
if (respay.status === 1) {
event.$refs.payDialog.showDialogHand("支付提示", "支付成功后请点击「支付已完成」按钮查看所购商品。如支付完成1分钟后仍显示异常请关闭当前窗口前往「我的」-「消费记录」查看订单状态。", "支付已完成", "关闭", async () => {
let resPayStatus = await getOrderStatus(data.data['order_num']);
if (resPayStatus.data == 1) {
event.$refs.payDialog.closeHand();
resolve('success');
} else {
uni.showToast({
title: resPayStatus.msg,
icon: 'none',
duration: 1000
});
}
});
event.$refs.payDialog.showDialogHand("支付提示",
"支付成功后请点击「支付已完成」按钮查看所购商品。如支付完成1分钟后仍显示异常请关闭当前窗口前往「我的」-「消费记录」查看订单状态。",
"支付已完成", "关闭", async () => {
let resPayStatus = await getOrderStatus(data.data['order_num']);
if (resPayStatus.data == 1) {
event.$refs.payDialog.closeHand();
resolve('success');
} else {
uni.showToast({
title: resPayStatus.msg,
icon: 'none',
duration: 1000
});
}
});
}
@ -134,7 +143,8 @@ class MiniProgramPlatform extends BasePlatform {
return new Promise((resolve, reject) => {
uni.chooseAddress({
success: res => {
res.detailed_address = res.provinceName + res.cityName + res.countyName + res.detailInfo;
res.detailed_address = res.provinceName + res.cityName + res.countyName +
res.detailInfo;
resolve(res)
},
fail: err => {
@ -188,6 +198,26 @@ class MiniProgramPlatform extends BasePlatform {
}
AppLaunch(options) {
console.log("AppLaunch", options);
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate);
});
updateManager.onUpdateReady(function(res) {
uni.showModal({
title: "更新提示",
content: "新版本已经准备好,是否重启应用?",
success(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function(res) {
// 新的版本下载失败
});
}
async getOrderNo(event) {
return new Promise(async (resolve, reject) => {
@ -217,7 +247,7 @@ class MiniProgramPlatform extends BasePlatform {
}
});
}
delOrderNo() { }
delOrderNo() {}
/**
* 重写获取用户中心菜单列表添加微信小程序特有菜单
@ -236,7 +266,7 @@ class MiniProgramPlatform extends BasePlatform {
path: '',
isCustomService: true,
// 客服按钮不需要处理函数,由微信小程序原生组件处理
handler: () => { }
handler: () => {}
};
// 将客服菜单插入到第二个位置

View File

@ -1,53 +1,65 @@
import MiniProgramPlatform from './MiniProgramPlatform';
//#ifdef APP-PLUS
import AppPlatform from './AppPlatform';
//#endif
//#ifdef WEB
import H5Platform from './H5Platform';
import WebAppPlatform from './WebAppPlatform';
//#endif
//#ifdef APP-IOS
import IOSPlatform from './IOSPlatform'
//#endif
class PlatformFactory {
static create() {
// 判断小程序环境
//#ifdef MP-WEIXIN
return new MiniProgramPlatform();
//#endif
static create() {
// 判断 App 环境
//#ifdef APP-ANDROID
return new AppPlatform();
//#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;
// 判断小程序环境
//#ifdef MP-WEIXIN
return new MiniProgramPlatform();
//#endif
// 判断 IOS环境
//#ifdef APP-IOS
return new IOSPlatform();
//#endif
// 判断 App 环境
//#ifdef APP-PLUS
return new AppPlatform();
//#endif
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
// 判断 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;
// 默认返回 小程序
return new MiniProgramPlatform();
}
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
// 默认返回 小程序
return new MiniProgramPlatform();
}
}
// 使用示例
const platform = PlatformFactory.create();
console.log(platform.env);
export { platform };
export {
platform
};

View File

@ -0,0 +1,107 @@
<template>
<view>
<web-view
ref="webview" :src="webUrl" :webview-styles="webviewStyles" @message="onMessage"
/>
</view>
</template>
<script>
export default {
components: {},
props: {
// prizeList props
},
data() {
const sysinfo = uni.getSystemInfoSync();
return {
hideviewStyles: {
height: "0px",
width: "0px",
},
webviewStyles: {
height: sysinfo.windowHeight + "px",
width: sysinfo.windowWidth+ "px",
},
// webUrl: 'https://zfunbox.cn/m/chou-box-luck.html',
webUrl:
"http://192.168.1.26:5500/%E5%85%AC%E5%8F%B8/%E5%B7%A5%E4%BD%9C/%E5%8F%8B%E8%BE%BE/%E8%90%BD%E5%9C%B0%E9%A1%B5/chou-box-luck.html",
};
},
computed: {
//
lotteryItemSize() {
let height = uni.upx2px(220);
let width = uni.upx2px(170);
return [width, height];
},
},
methods: {
getWebview() {
const currentWebview = this.$scope.$getAppWebview();
console.log("收到网页消息:",currentWebview.children());
const webview = currentWebview.children()[0]; // webview
return webview;
},
setWebviewAction(action, data) {
const webview = this.getWebview(); // webview
//data objectarrayjson
if (typeof data === "object") {
data = JSON.stringify(data);
}
//data arrayjson
if (Array.isArray(data)) {
data = JSON.stringify(data);
}
console.log(
"setWebviewActionsetWebviewActionsetWebviewAction",
action,
data
);
webview.evalJS('OnMessage("' + action + '","' + data + '");');
},
onMessage(event) {
console.log("收到网页消息:", event);
const data = event.detail.data[0];
if (data.action === "skip") {
//
uni.showToast({
title: "跳过动画",
icon: "none",
});
} else if (data.action === "load") {
//
uni.showToast({
title: "初始化",
icon: "none",
});
//
this.setWebviewAction("addPrizeImage", [{}]);
} else {
console.log(data);
uni.showToast({
title: data.msg,
icon: "none",
});
}
},
evalJs() {
const webview = this.getWebview(); // webview
if (webview) {
// webview.
// webview.evalJS('start();');
} else {
console.error("未找到子 WebView");
}
},
},
mounted() {
//
},
};
</script>
<style lang="scss" scoped></style>

View File

@ -16,6 +16,7 @@
<view class="skip-animation" @click="skipAnimation" :style="[skipButtonStyle()]">跳过动画</view>
</view>
<DetailGrandPrize ref="detailGrandPrize" @end="onLuckyEnd1" />
</view>
</template>

23
main.js
View File

@ -48,28 +48,7 @@ function loadScript(url) {
loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js')
// #endif
// #ifdef MP-WEIXIN
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
})
// #endif
Vue.config.productionTip = false
Vue.mixin(Mixin)

View File

@ -413,6 +413,12 @@
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/other/web-detail-lucky",
"style": {
"navigationStyle": "custom"
}
}
],
"subPackages": [{
@ -491,7 +497,9 @@
"navigationBarBackgroundColor": "#222222",
"backgroundColor": "#000000"
},
"usingComponents": {},
"usingComponents": {
"web-view": "pages/other/web-detail-lucky"
},
"tabBar": {
"custom": true,
"color": "#CCCCCC",

View File

@ -0,0 +1,41 @@
<template>
<page-container title="抽奖动画" :showBack="false">
<DetailLuckyWeb ref="lottery" @end="onLuckyEnd"></DetailLuckyWeb>
<button @click="Init">初始化</button>
<button @click="LoadImage">加载图片</button>
<button>设置模式</button>
<button @click="SetSize">跳转大小</button>
</page-container>
</template>
<script>
import PageContainer from '@/components/page-container/page-container.vue'
import DetailLuckyWeb from '@/components/detail-lucky/detail-lucky-web.vue';
export default {
components: {
PageContainer,
DetailLuckyWeb
},
data() {
return {
}
},
onLoad() {
},
methods: {
onLuckyEnd(e) {
console.log('抽奖结束');
},
Init() { },
LoadImage() { },
SetSize() {
console.log(this.$refs.lottery);
this.$refs.lottery.setWebViewSize();
},
}
}
</script>
<style scoped></style>

View File

@ -5,7 +5,7 @@
-->
<template>
<view class="content">
<view class="navLeft align-center" :style="{ top: $sys().statusBarHeight + 'px' }" @tap="$c.back(1)">
<view class="navLeft align-center" :style="{ top: $sys().statusBarHeight + 'px' }" @tap="jumapSlots()">
<view class="flex" style="width: 100%">
<view class="title1" style="width: 166rpx; height: 64rpx; margin-top: 5rpx;" >
<image :src="$img1('common/home_logo.png')" style="width: 166rpx; height: 64rpx;" mode="" ></image>
@ -422,7 +422,7 @@ export default {
},
jumapSlots(){
this.$customRouter.navigateTo("/pages/shouye/slots");
this.$customRouter.navigateTo("/pages/other/web-detail-lucky");
}
},
};