浏览代码

fix(wx): route default banner to FAQ

Developer 1 周之前
父节点
当前提交
e0a06d006b
共有 3 个文件被更改,包括 45 次插入 和 12 次删除
  1. 10 12
      pages/home.vue
  2. 24 0
      tests/homeBannerAction.test.js
  3. 11 0
      utils/homeBannerAction.js

+ 10 - 12
pages/home.vue

@@ -133,6 +133,7 @@
 
 <script>
 	import Tabbar from '@/components/CusTabbar/index.vue'
+	import { resolveHomeBannerAction } from '@/utils/homeBannerAction.js'
 	export default {
 		components:{ Tabbar },
 		data(){
@@ -216,18 +217,15 @@
 				})
 			},
 			bannerClick(e){
-				let banner = this.bannerOrigin[e];
-				if(banner&&banner?.redirect){
-					if(banner?.redirectType==1){//微信公众号
-						uni.navigateTo({
-							url:'/pages/webView?src='+banner?.redirect
-						})
-					}else if(banner?.redirectType==2){//微信小程序
-						uni.navigateToMiniProgram({
-							appId:banner?.redirect
-						})
-					}
-				}
+				const action = resolveHomeBannerAction(this.bannerOrigin[e])
+				if(!action) return
+				if(action.type==='html') return this.openHtml(action.filename)
+				if(action.type==='web') return uni.navigateTo({
+					url:'/pages/webView?src='+action.url
+				})
+				if(action.type==='miniProgram') return uni.navigateToMiniProgram({
+					appId:action.appId
+				})
 			},
 			toTurn(url){
 				if(!url) return 

+ 24 - 0
tests/homeBannerAction.test.js

@@ -0,0 +1,24 @@
+const assert = require('node:assert/strict')
+const { resolveHomeBannerAction } = require('../utils/homeBannerAction')
+
+assert.deepEqual(resolveHomeBannerAction(), {
+	type: 'html',
+	filename: 'PERILL常见问题与支持.html'
+})
+assert.deepEqual(resolveHomeBannerAction({
+	redirectType: 1,
+	redirect: 'https://example.com/activity'
+}), {
+	type: 'web',
+	url: 'https://example.com/activity'
+})
+assert.deepEqual(resolveHomeBannerAction({
+	redirectType: 2,
+	redirect: 'wx123456'
+}), {
+	type: 'miniProgram',
+	appId: 'wx123456'
+})
+assert.equal(resolveHomeBannerAction({ redirectType: 1 }), null)
+
+console.log('home banner action rules: PASS')

+ 11 - 0
utils/homeBannerAction.js

@@ -0,0 +1,11 @@
+const FAQ_PAGE = 'PERILL常见问题与支持.html'
+
+function resolveHomeBannerAction(banner) {
+	if (!banner) return { type: 'html', filename: FAQ_PAGE }
+	if (!banner.redirect) return null
+	if (Number(banner.redirectType) === 1) return { type: 'web', url: banner.redirect }
+	if (Number(banner.redirectType) === 2) return { type: 'miniProgram', appId: banner.redirect }
+	return null
+}
+
+module.exports = { FAQ_PAGE, resolveHomeBannerAction }