This commit is contained in:
zpc 2025-06-24 18:51:21 +08:00
parent e544788855
commit db374522f7
10 changed files with 145 additions and 32 deletions

View File

@ -1,4 +1,4 @@
import { getPlatformConfig } from '../server/config';
/**
* 多端平台抽象基类父类
* 定义所有端必须实现的方法
@ -12,10 +12,18 @@ class BasePlatform {
this.env = ''; // 运行环境标识
this.config = null;
this.version = '1.0.0';
this.getConfigPromise = null;
}
async getConfig() {
return {};
return new Promise(async (resolve, reject) => {
if (this.config) {
resolve(this.config);
} else {
this.config = await getPlatformConfig(this.version);
resolve(this.config);
}
});;
}
async appData() {

View File

@ -1,4 +1,5 @@
import HttpRequest from "../system/request";
import { platform } from "../platform/PlatformFactory";
/**
* 获取系统配置
@ -8,3 +9,12 @@ export const getConfig = async () => {
const res = await HttpRequest.getOrCache('/config');
return res.data;
}
/**
* 获取平台配置
* @param {string} version 版本号
* @returns
*/
export const getPlatformConfig = async () => {
const res = await HttpRequest.getOrCache('/getPlatformConfig', { version: platform.version }, 500);
return res.data;
}

View File

@ -24,6 +24,8 @@ export const getAgreement = async (type) => {
type_id = 5;
} else if (type == "product") {
type_id = 32;
} else {
type_id = type;
}
const res = await HttpRequest.get('/getAgreement', {
type: type_id

View File

@ -197,11 +197,13 @@ class HttpRequest {
*/
static async getOrCache(url, data = {}, time = 300, showLoading = false) {
const cacheKey = 'cache_' + url + '_' + qs.stringify(data);
// console.log('getOrCache', cacheKey, '查询缓存');
const cacheData = getLocalStorage(cacheKey);
if (cacheData) {
console.log('getOrCache', cacheKey, '缓存命中');
return cacheData;
}
const res = await HttpRequest.request(url, data, 'GET', showLoading);
setLocalStorage(cacheKey, res, time);
return res;

View File

@ -10,10 +10,20 @@
</template>
<script setup>
import { defineComponent, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getConfig } from '@/common/server/config';
import { navigateTo } from '@/common/system/router';
import {
defineComponent,
ref
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app'
import {
getConfig, getPlatformConfig
} from '@/common/server/config';
import {
navigateTo
} from '@/common/system/router';
let icon = ref("/static/app-plus/icon_108.png");
let login_icon = ref("/static/app-plus/index_login.gif");
let tips_text = ref("正在加载中。。。");
@ -26,10 +36,13 @@ onLoad(async () => {
uni.onNetworkStatusChange(checkNetwork);
return;
}
// navigateTo('/pages/news/news');
navigateTo('/pages/other/user-agreement?type=user');
const config = await getPlatformConfig();
console.log("config", config);
if (config.buildVersion == "105") {
navigateTo('/pages/news/news');
} else {
navigateTo('/pages/other/user-agreement');
}
});
/**
* 检查网络状态
@ -46,6 +59,7 @@ function checkNetwork(res) {
tips_text.value = '请检查网络连接';
}
}
</script>
<style lang="scss">

View File

@ -70,7 +70,7 @@
</view>
</view>
<template #empty>
<no-data />
</template>
@ -79,6 +79,8 @@
</template>
</z-paging>
</z-paging-swiper>
<!-- 使用支付弹窗组件 -->
<payment-popup ref="paymentPopup_ref" :onSuccess="onPaymentSuccess" />
</template>
<script setup>
@ -86,6 +88,7 @@ import { ref } from 'vue';
const paging = ref(null);
import { getProductList, getBannerList } from '@/common/server/product';
import TextSearch from '@/components/youdas-container/text-search.vue';
import paymentPopup from '@/components/youdas-container/payment-popup.vue';
//
const topDataList = ref([
@ -93,7 +96,7 @@ const topDataList = ref([
let isSearch = ref(false);
const dataList = ref([]);
const searchKeyword = ref(''); //
let paymentPopup_ref = ref(null);
//
const goToDetail = (item) => {
uni.navigateTo({
@ -103,8 +106,7 @@ const goToDetail = (item) => {
//
const buyProduct = (item, event) => {
//
event.stopPropagation();
//
if (item.stock <= 0) {
@ -114,12 +116,12 @@ const buyProduct = (item, event) => {
});
return;
}
paymentPopup_ref.value.open(item.id);
//
uni.showToast({
title: '已添加到购物车',
icon: 'success'
});
// uni.showToast({
// title: '',
// icon: 'success'
// });
};
//
@ -151,6 +153,15 @@ onLoad(async () => {
const bannerList = await getBannerList();
topDataList.value = bannerList;
});
const onPaymentSuccess = () => {
uni.showToast({
title: '支付成功',
icon: 'success'
});
paymentPopup_ref.value.close();
paging.value.reload();
//
};
</script>
<style lang="scss">

View File

@ -157,6 +157,13 @@ const loadMenu = async () => {
},
{
id: 5,
title: "商品退换货",
onClick: (res) => {
yds.navigateToAgreement("29");
}
},
{
id: 6,
title: "用户协议",
onClick: (res) => {
yds.navigateToAgreement("user");
@ -206,7 +213,7 @@ const loadMenu = async () => {
<style lang="scss">
.content {
width: 100%;
height: 100vh;
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: #F7F7F7;

View File

@ -24,6 +24,7 @@ const loadData = async (type) => {
pageTitle.value = "隐私政策";
}
const res = await getAgreement(type);
console.log("res", res);
if (res) {
agreementContent.value = res.content;
if (pageTitle.value == "") {

View File

@ -0,0 +1,70 @@
<template>
<view class="container">
<view class="navbar" :style="{ 'height': statusBarHeight }"></view>
<web-view v-if="webviewurl" ref="webview" class="webview" :src="webviewurl"
@onPostMessage="handlePostMessage"></web-view>
</view>
</template>
<script setup>
import {
ref
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app'
import {
platform
} from '@/common/platform/PlatformFactory';
import {
getPlatformConfig
} from '@/common/server/config';
let webview = ref(null);
let webviewurl = ref("");
getPlatformConfig().then(res => {
webviewurl.value = res.userAgreement;
});
const windowInfo = uni.getWindowInfo();
console.log(windowInfo);
let statusBarHeight = windowInfo.statusBarHeight + "px";
// webview向外部发送消息
const handlePostMessage = async (data) => {
console.log("接收到消息:", data, data.detail.data);
if (data.detail.data && data.detail.data[0]) {
let detailData = data.detail.data[0];
if (detailData.action == "pay") {
const res = await platform.pay(detailData.data);
evalJs({
action: "pay",
data: res.isPay,
callback: detailData.callback
});
}
}
}
// 调用 webview 内部逻辑
const evalJs = (data) => {
let json = JSON.stringify(data || {});
console.log("yds_postMessage", json);
webview.value.evalJS("window.yds_postMessage('" + json + "')");
}
</script>
<style>
.container {
flex: 1;
flex-direction: column;
/* 竖向排列 */
}
.navbar {
height: 40px;
/* 导航栏高度 */
background-color: #fff;
}
.webview {
flex: 1;
/* 自动占满剩余空间 */
}
</style>

View File

@ -1,12 +0,0 @@
<template>
<web-view :src="url"></web-view>
</template>
<script setup>
let url = ref("");
onLoad((options) => {
url.value = "http://testweb.zfunbox.cn/";
});
</script>
<style lang="scss" scoped></style>