yds
This commit is contained in:
parent
69b5adb1aa
commit
deb4471299
5
App.vue
5
App.vue
|
|
@ -132,6 +132,11 @@ uni-tabbar {
|
|||
z-index: 97 !important;
|
||||
}
|
||||
|
||||
uni-tabbar .uni-tabbar__icon img{
|
||||
height: 24px !important;
|
||||
width: 24px !important;
|
||||
}
|
||||
|
||||
/* 引入字体 */
|
||||
@font-face {
|
||||
font-family: "YouSheBiaoTiHei";
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ const testing = {
|
|||
|
||||
|
||||
// 根据环境变量选择对应配置
|
||||
let currentEnv = production;//production;//testing;//production_wz;
|
||||
let currentEnv = testing;//production;//testing;//production_wz;
|
||||
// 衍生配置
|
||||
const config = {
|
||||
...currentEnv,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class AppPlatform extends BasePlatform {
|
|||
async appData() {
|
||||
this.getConfig().then(res => {
|
||||
console.log("AppLaunch", res);
|
||||
if (res.isCheck) {
|
||||
if (res.buildVersion=="105") {
|
||||
console.log("开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式");
|
||||
uni.setTabBarItem({
|
||||
index: 0,
|
||||
|
|
@ -334,7 +334,7 @@ class AppPlatform extends BasePlatform {
|
|||
uni.removeStorageSync('userinfo');
|
||||
that.getConfig().then(res => {
|
||||
console.log("AppLaunch", res);
|
||||
if (!res.isCheck) {
|
||||
if (res.buildVersion == "105") {
|
||||
uni.switchTab({
|
||||
url: '/pages/shouye/index'
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class H5Platform extends BasePlatform {
|
|||
this.env = 'h5';
|
||||
// 简单初始化
|
||||
let erudaInstance = uni.getStorageSync("erudaInstance");
|
||||
|
||||
if (erudaInstance != null && erudaInstance != "") {
|
||||
this.startDeb();
|
||||
}
|
||||
|
|
@ -169,7 +170,7 @@ class H5Platform extends BasePlatform {
|
|||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if (window.location.pathname == "/" || window.location.pathname == "/pages/index/index") {
|
||||
// uni.switchTab({
|
||||
// url: '/pages/shouye/index'
|
||||
|
|
|
|||
87
common/platform/NewWebAppPlatform.js
Normal file
87
common/platform/NewWebAppPlatform.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import BasePlatform from './BasePlatform';
|
||||
import H5Platform from './H5Platform';
|
||||
import { webAppPay } from '@/common/webapp.js'
|
||||
|
||||
|
||||
class NewWebAppPlatform extends H5Platform {
|
||||
constructor() {
|
||||
super();
|
||||
this.code = 'WEB_APP_ANDROID';
|
||||
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}`);
|
||||
}
|
||||
pay({
|
||||
data
|
||||
}, event) {
|
||||
console.log(this, event);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const res = await webAppPay(data);
|
||||
if (!res) {
|
||||
uni.showToast({
|
||||
title: '取消支付',
|
||||
icon: 'none',
|
||||
duration: 500,
|
||||
success: () => {
|
||||
/* 取消订单 */
|
||||
resolve('cancel')
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'success',
|
||||
duration: 500,
|
||||
success: () => {
|
||||
resolve('success')
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
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();
|
||||
|
||||
// 添加客服菜单项(仅微信小程序)
|
||||
|
||||
|
||||
// 将客服菜单插入到第二个位置
|
||||
return [...baseMenuList.slice(0, baseMenuList.length - 1), ...baseMenuList.slice(baseMenuList.length - 1)];
|
||||
}
|
||||
getVersion() {
|
||||
return uni.getStorageSync('version') == '' ? '1.0.0' : uni.getStorageSync('version');
|
||||
}
|
||||
}
|
||||
export default NewWebAppPlatform;
|
||||
|
|
@ -9,6 +9,7 @@ import IOSPlatform from './IOSPlatform';
|
|||
//#ifdef WEB
|
||||
import H5Platform from './H5Platform';
|
||||
import WebAppPlatform from './WebAppPlatform';
|
||||
import NewWebAppPlatform from './NewWebAppPlatform';
|
||||
//#endif
|
||||
class PlatformFactory {
|
||||
static create() {
|
||||
|
|
@ -24,7 +25,7 @@ class PlatformFactory {
|
|||
//#endif
|
||||
// 判断 App 环境
|
||||
//#ifdef APP
|
||||
|
||||
|
||||
return new AppPlatform();
|
||||
//#endif
|
||||
|
||||
|
|
@ -33,36 +34,53 @@ class PlatformFactory {
|
|||
// 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;
|
||||
let is_web_app = this.checkIsWebApp();
|
||||
let is_new_web_app = this.checkIsNewWebApp();
|
||||
|
||||
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();
|
||||
}
|
||||
if (is_new_web_app) {
|
||||
return new NewWebAppPlatform();
|
||||
}
|
||||
return new H5Platform();
|
||||
//#endif
|
||||
|
||||
// 默认返回
|
||||
return new BasePlatform();
|
||||
}
|
||||
|
||||
static checkIsWebApp() {
|
||||
return this.checkPlatformType('is_web_app');
|
||||
}
|
||||
|
||||
static checkIsNewWebApp() {
|
||||
return this.checkPlatformType('is_new_web_app','cb20xad0e35094521ae46a1d1fb0ddd1');
|
||||
}
|
||||
|
||||
static checkPlatformType(storageKey, codeValue = 'cb2039d0e35094521ae46a1d11b0ddd1') {
|
||||
let isPlatformType = uni.getStorageSync(storageKey);
|
||||
let search = window.location.search;
|
||||
|
||||
if (search != null && search != '') {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const code = searchParams.get('_p');
|
||||
if (code && code == codeValue) {
|
||||
uni.setStorageSync(storageKey, true);
|
||||
isPlatformType = true;
|
||||
}
|
||||
}
|
||||
if (uni.getStorageSync(storageKey) != null && uni.getStorageSync(storageKey) != '') {
|
||||
isPlatformType = true;
|
||||
}
|
||||
|
||||
return isPlatformType;
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
const platform = PlatformFactory.create();
|
||||
// console.log(platform.env,"获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台");
|
||||
// console.log(platform.env,"获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台");
|
||||
export {
|
||||
platform
|
||||
};
|
||||
|
|
@ -48,4 +48,63 @@ export function msg(msg) {
|
|||
duration,
|
||||
position,
|
||||
});
|
||||
};
|
||||
};
|
||||
/**
|
||||
* 生成GUID
|
||||
* @returns {string} 返回格式为'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'的GUID
|
||||
*/
|
||||
export function generateGUID() {
|
||||
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 生成指定长度的随机GUID
|
||||
* @param {Number} length 指定GUID的长度
|
||||
* @returns {string} 返回指定长度的随机GUID
|
||||
*/
|
||||
export function generateGUIDWithLength(length = 32) {
|
||||
let guid = '';
|
||||
const characters = 'abcdef0123456789';
|
||||
|
||||
// 生成指定长度的随机字符
|
||||
for (let i = 0; i < length; i++) {
|
||||
guid += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
|
||||
// 如果长度大于等于36,则添加破折号使其格式类似标准GUID
|
||||
if (length >= 36) {
|
||||
return guid.substring(0, 8) + '-' +
|
||||
guid.substring(8, 12) + '-' +
|
||||
guid.substring(12, 16) + '-' +
|
||||
guid.substring(16, 20) + '-' +
|
||||
guid.substring(20, 32) +
|
||||
guid.substring(32);
|
||||
}
|
||||
|
||||
return guid;
|
||||
}
|
||||
/**
|
||||
* 生成固定长度的随机字符串
|
||||
* @param {Number} length 字符串长度,默认为16
|
||||
* @param {Boolean} includeSpecial 是否包含特殊字符,默认为false
|
||||
* @returns {string} 返回生成的随机字符串
|
||||
*/
|
||||
export function generateRandomString(length = 16, includeSpecial = false) {
|
||||
let result = '';
|
||||
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
// 如果需要包含特殊字符
|
||||
if (includeSpecial) {
|
||||
characters += '!@#$%^&*()_+~`|}{[]:;?><,./-=';
|
||||
}
|
||||
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
80
common/webapp.js
Normal file
80
common/webapp.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { generateRandomString } from '@/common/util.js'
|
||||
document.addEventListener('UniAppJSBridgeReady', function () {
|
||||
// alert('aaa1')
|
||||
ydsApp.getEnv(function (res) {
|
||||
console.log('当前环境:' + JSON.stringify(res));
|
||||
ydsApp.postMessage({
|
||||
data: {
|
||||
action: 'load',
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
const _ydsApp = {
|
||||
callback: {}
|
||||
}
|
||||
window.yds_postMessage = function (data) {
|
||||
// 检查data是否为字符串类型
|
||||
console.log('yds_postMessageyds_postMessageyds_postMessageyds_postMessage', data);
|
||||
if (typeof data === 'string') {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.log('数据解析失败:', e);
|
||||
return; // 解析失败,退出函数
|
||||
}
|
||||
}
|
||||
|
||||
if (data.action == "pay") {
|
||||
if (_ydsApp.callback[data.callback]) {
|
||||
_ydsApp.callback[data.callback](data.data);
|
||||
delete _ydsApp.callback[data.callback];
|
||||
return;
|
||||
}
|
||||
console.log('回调不存在');
|
||||
}
|
||||
}
|
||||
//返回按钮
|
||||
window.yds_backPress = function () {
|
||||
uni.navigateBack();
|
||||
}
|
||||
export const home = () => {
|
||||
if (window.ydsApp) {
|
||||
console.log('加载webapp-成功');
|
||||
} else {
|
||||
console.log('加载webapp-未加载');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const webAppPay = (orderInfo) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!window.ydsApp) {
|
||||
reject('ydsApp未加载');
|
||||
return;
|
||||
}
|
||||
let callback = generateRandomString(16);
|
||||
_ydsApp.callback[callback] = resolve;
|
||||
ydsApp.postMessage({
|
||||
data: {
|
||||
action: 'pay',
|
||||
data: orderInfo,
|
||||
callback: callback
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const webAppPageUrl = (url, isHome) => {
|
||||
if (!window.ydsApp) {
|
||||
reject('ydsApp未加载');
|
||||
return;
|
||||
}
|
||||
ydsApp.postMessage({
|
||||
data: {
|
||||
action: 'pageUrl',
|
||||
data: { page: url, isHome: isHome },
|
||||
}
|
||||
})
|
||||
}
|
||||
31
common/ydsmixin.js
Normal file
31
common/ydsmixin.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { webAppPageUrl } from '@/common/webapp.js';
|
||||
let home = ["pages/hegui/hegui",
|
||||
"pages/shouye/index",
|
||||
"pages/mall/index",
|
||||
"pages/infinite/index",
|
||||
"pages/user/index"
|
||||
];
|
||||
const ydsMixin = {
|
||||
onShow() {
|
||||
//#ifdef H5
|
||||
try {
|
||||
var pages = getCurrentPages();
|
||||
if (pages && pages.length > 0) {
|
||||
let tempPage = pages[pages.length - 1];
|
||||
// tempPage.route
|
||||
let isHome = home.includes(tempPage.route);
|
||||
console.log('当前页面位置', tempPage.route, isHome);
|
||||
webAppPageUrl(tempPage.route, isHome);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('ydsMixin-onShow-error', e);
|
||||
}
|
||||
|
||||
//#endif
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default ydsMixin;
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
|
||||
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<script type="text/javascript" src="https://image.zfunbox.cn/app/webjs/uni.webview.1.5.2.1.js"></script>
|
||||
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
18
main.js
18
main.js
|
|
@ -2,6 +2,10 @@ import Vue from 'vue'
|
|||
import App from './App'
|
||||
import Mixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js'
|
||||
import common from '@/common/common.js'
|
||||
// #ifdef H5
|
||||
import { home } from '@/common/webapp.js'
|
||||
import ydsMixin from '@/common/ydsmixin.js'
|
||||
// #endif
|
||||
import {
|
||||
gotopage
|
||||
} from '@/common/gotopage.js'
|
||||
|
|
@ -42,19 +46,15 @@ Vue.prototype.req = RequestManager.request
|
|||
Vue.prototype.$request = RequestManager
|
||||
|
||||
// #ifdef H5
|
||||
function loadScript(url) {
|
||||
var script = document.createElement('script')
|
||||
script.type = 'text/javascript'
|
||||
script.src = url
|
||||
document.head.appendChild(script)
|
||||
}
|
||||
|
||||
loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js')
|
||||
home();
|
||||
// #endif
|
||||
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.mixin(Mixin)
|
||||
Vue.mixin(Mixin);
|
||||
// #ifdef H5
|
||||
Vue.mixin(ydsMixin);
|
||||
// #endif
|
||||
App.mpType = 'app'
|
||||
|
||||
const app = new Vue({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name" : "友达赏王者",
|
||||
"appid" : "__UNI__2E6CB39",
|
||||
"appid" : "__UNI__0BC0425",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.2",
|
||||
"versionCode" : 102,
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@
|
|||
"borderStyle": "black",
|
||||
"backgroundColor": "#FFFFFF",
|
||||
"iconWidth": "24px",
|
||||
"iconHeight": "24px",
|
||||
// "iconHeight": "10px",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/shouye/index",
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@
|
|||
<view class="test-mode-item">
|
||||
<text>日志状态: {{ logEnabled ? '已开启' : '已关闭' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="test-mode-item">
|
||||
<text>环境: {{ $platform.env }}--{{ $platform.code }}</text>
|
||||
</view>
|
||||
<view class="test-mode-item">
|
||||
<view class="button-group">
|
||||
<button class="test-button log-button" @click="enableLog">开启日志</button>
|
||||
|
|
@ -65,7 +67,8 @@ export default {
|
|||
isTestMode: false,
|
||||
logEnabled: false,
|
||||
version: '',
|
||||
domain: ''
|
||||
domain: '',
|
||||
env: ''
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue
Block a user