Sfoglia il codice sorgente

全局跳转函数,投票详情页和首页跳转修改

yfso 2 anni fa
parent
commit
237de2c4b7
6 ha cambiato i file con 230 aggiunte e 100 eliminazioni
  1. 2 1
      manifest.json
  2. 39 11
      pages/index/index.vue
  3. 29 86
      pages/index/vote-detail/index.vue
  4. 15 0
      setting - 副本.js
  5. 1 1
      setting.js
  6. 144 1
      utils/tools.js

+ 2 - 1
manifest.json

xqd
@@ -68,7 +68,8 @@
                 "desc" : "获取位置,推荐精彩信息"
             }
         },
-        "requiredPrivateInfos" : [ "getLocation", "chooseLocation" ]
+        "requiredPrivateInfos" : [ "getLocation", "chooseLocation" ],
+		"lazyCodeLoading": "requiredComponents"
     },
     "mp-alipay" : {
         "usingComponents" : true

+ 39 - 11
pages/index/index.vue

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -7,7 +7,10 @@
 				<swiper class="swiper-box" @change="change1" circular>
 					<swiper-item v-for="(item ,index) in infoList" :key="index">
 						<view class="swiper-item" v-if="item.resource_type == 1"
-							@click="jumpHAppID(item.jump_type,item.jump_config)">
+							@click="$utils.jump({
+								jump_type: item.jump_type,
+								jump_config: item.jump_config
+							})">
 							<image style="width: 100%;height:592rpx;" :src="item.img" mode="aspectFill"></image>
 						</view>
 						<view class="swiper-item" v-if="item.resource_type == 2">
@@ -23,7 +26,10 @@
 		<!-- 金刚图 -->
 		<view class="home-nav">
 			<view class="home-nav-item" v-for="(item,index) in navList" :key="index"
-				@click="jumpHAppID(item.jump_type,item.jump_config)">
+				@click="$utils.jump({
+					jump_type: item.jump_type,
+					jump_config: item.jump_config
+				})">
 				<image style="width: 101.96rpx;height: 103.96rpx;" :src="item.img" mode=""></image>
 				<text style="color: #333;font-size: 24rpx;margin-top: 18rpx; ">{{item.title}}</text>
 			</view>
@@ -47,7 +53,11 @@
 		<!-- 活动图片 -->
 		<view class="home-special-img">
 			<template v-for="(item,index) in specialList" >
-				<view class="ListItem" v-if="item.show_status" :key="index" @click="activeDetail(item.id)">
+				<view class="ListItem" v-if="item.show_status" :key="index" @click="$utils.jump({
+					jump_type: 3,
+					jump_config: '/pages/index/active-detail/index',
+					id: item.id,
+				})">
 					<image style="width: 312rpx;height: 200rpx; border-radius: 12rpx; "
 						:src="item.banners?item.cover_img:'http://t9.9026.com/imgs/Kudosbg.png'" mode=""></image>
 					<view class="kudosicon" @click.stop="kudosActive(item.id,index)">
@@ -64,7 +74,11 @@
 		<!-- 广告图 -->
 		<view class="home-banner" v-if="!isShowAdver">
 			<view class="home-banner-img" v-if="in_page==1 && type == 1 ">
-				<image style="width: 100%; height: 576rpx; border-radius: 12rpx;" :src="advData.img" mode="" @click="jumpHAppID(advData.jump_type, advData.jump_config)"></image>
+				<image style="width: 100%; height: 576rpx; border-radius: 12rpx;" :src="advData.img" mode="" 
+				@click="$utils.jump({
+					jump_type: item.jump_type,
+					jump_config: item.jump_config
+				})"></image>
 				<image @click="cleanCoverImg" class="img-clean" style="width: 20rpx; height: 20rpx; "
 					src="/static/icon/clean.png" mode="">
 				</image>
@@ -84,14 +98,19 @@
 
 		<movable-area class="movableArea">
 			<movable-view class="movableView" direction="all" x="630rpx" y="700rpx">
-				<view class="img-IHg" @click="goJoin">
+				<view class="img-IHg" @click="$utils.jumpJoinVip()">
 					<image style="width: 64rpx; height: 58rpx; " src="/static/icon/vip.png" mode=""></image>
 				</view>
 			</movable-view>
 		</movable-area>
 
 		<!-- 广告的附图 -->
-		<view class="home-attach" @click="jumpHAppID(advInsetImg.jump_type, advInsetImg.jump_config)">
+		<view class="home-attach" 
+			@click="$utils.jump({
+				jump_type: advInsetImg.jump_type,
+				jump_config: advInsetImg.jump_config
+			})"
+		>
 			<image style="width: 690rpx;height: 156rpx;border-radius: 79rpx;" :src="advInsetImg.img" mode=""></image>
 		</view>
 		<!-- 酒店推荐 -->
@@ -110,7 +129,7 @@
 				<!-- <view @click="produceDetail(item.id)" class="home-hotel-img-content-item" v-for="(item,index) in goodsList" :key="index"
 					:style="{marginTop:item.marginTop || 0 }">
 					<image class="home-hotel-img-content-item-img"
-						:class="item.short?'home-hotel-img-content-item-img': 'home-hotel-img-content-item-img-long' "
+						:class="item.short?'home-hotel-img-content-item-img': 'homel-hotel-img-content-item-img-long' "
 						:src="item.cover_img" mode=""></image>
 					<view class="text">
 						<text class="text-top">{{item.name}}</text>
@@ -125,7 +144,10 @@
 					</view>
 				</view>
 			</view>
-			<view class="home-hotel-img-more" @click="goProduceList">
+			<view class="home-hotel-img-more" @click="$utils.jump({
+				jump_type: 4,
+				jump_config: '/pages/goods/goods'
+			})">
 				<text>查看更多商品</text>
 			</view>
 		</view>
@@ -144,7 +166,11 @@
 				<swiper class="swiper-box" circular @change="change2">
 					<swiper-item v-for="(items ,index) in info" :key="index">
 						<view v-for="(item ,j) in items" :key="j" class="swiper-item"
-							@click="jumpHAppID(item.jump_type,item.jump_config)">
+							@click="$utils.jump({
+								jump_type: item.jump_type,
+								jump_config: item.jump_config
+							})"
+						>
 							<image style="width:144rpx;height:142rpx;" :src="item.img" mode="aspectFill"></image>
 						</view>
 					</swiper-item>
@@ -159,7 +185,10 @@
 		<!-- 弹窗广告 -->
 		<uni-popup ref="popup" type="center">
 			<view class="popup-banner">
-				<image @click="jumpHAppID(popupData.jump_type, popupData.jump_config)" style="width: 656rpx;height: 916rpx;border-radius: 12rpx;" :src="popupData.img">
+				<image @click="$utils.jump({
+						jump_type: popupData.jump_type,
+						jump_config: popupData.jump_config
+				})" style="width: 656rpx;height: 916rpx;border-radius: 12rpx;" :src="popupData.img">
 				</image>
 				<view class="popup-banner-clean" @click='closePopupBanner'>
 					<image style="width: 20rpx; height: 20rpx; " src="/static/icon/clean.png" mode="">
@@ -292,7 +321,6 @@
 			this.admin = this.$store.getters.userInfo
 		},
 		onLoad() {
-
 			// this.getGoodsList()
 			this.getAllSet()
 		},

+ 29 - 86
pages/index/vote-detail/index.vue

xqd xqd xqd
@@ -267,11 +267,9 @@
 
 			//去兑换页面
 			goConvert() {
-				uni.navigateTo({
-					url: '/pages/my/prize/prize',
-					fail:(err)=>{
-						console.log(err)
-					}
+				this.$utils.jump({
+					jump_type: 4,
+					jump_config: '/pages/my/prize/prize'
 				})
 			},
 
@@ -336,48 +334,10 @@
 
 			//轮播图跳转h5或者小程序和内部页面
 			goSwiperSmall() {
-				//跳转h5
-				if (this.jump_type == 1) {
-					const url = this.jump_config; // 跳转的外链
-					const navtitle = 'H5'; // 这个标题是你自己可以设置的
-					uni.navigateTo({
-						// 跳转到webview页面
-						url: `/pages/webview/webview?url=${url}&nav=${navtitle}`,
-						success: () => {
-							console.log('成功')
-						},
-						fail: (e) => {
-							console.log(e, "失败")
-						}
-					});
-				} else if (this.jump_type == 2) {
-					let obj = JSON.parse(this.jump_config);
-					wx.navigateToMiniProgram({
-						appId: `${obj.appid}`, //appid
-						path: `${obj.path}`, //path
-						extraData: { //参数
-							foo: 'bar'
-						},
-						// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
-						success(res) {
-							console.log('成功')
-							// 打开成功
-						},
-						fail(e) {
-							console.log(e, '失败')
-						}
-					})
-				} else if (this.jump_type == 4) {
-					let obj = this.jump_config
-					uni.reLaunch({
-						url: obj,
-						fail:(err)=>{
-							uni.navigateTo({
-								url: obj
-							})
-						}
-					})
-				}
+				this.$utils.jump({
+					jump_type: this.jump_type,
+					jump_config: this.jump_config
+				})
 			},
 			cancelTime(i, j) {
 				let nowtime = new Date() //获取当前时间
@@ -432,46 +392,29 @@
 
 			// 跳转其他小程序
 			goJoin() {
-				let _this = this
-				wx.navigateToMiniProgram({
-					appId: 'wx255b58f0992b3c53', //appid
-					path: 'newUIMain/enrollment/enrollment', //path
-					extraData: { //参数
-						foo: 'bar'
-					},
-					// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
-					success(res) {
-						let page = _this.getPageUrl()
-						let user_id = ''
-						if (_this.admin != null) {
-							user_id = _this.admin.id
-						} else {
-							user_id = 0
-						}
-						console.log('成功', page)
-						_this.$api.my.userMemberAdd({
-							user_id,
-							page,
-						}).then(res => {
-							console.log(res.data);
-						})
-						
-						//增加票数
-						_this.$api.my.userJoinVip({
-							source_type: 1,
-							source_id: _this.sourceId
-						}).then(res => {
-							uni.setStorage({
-								key: 'is_vip',
-								data: 1,
-							});
-							_this.is_vip = true
-						})
-						// 打开成功
-					},
-					fail(e) {
-						console.log(e, '失败')
+				this.$utils.jumpJoinVip().then( _=>{
+					const page = this.getPageUrl()
+					let user_id = ''
+					if (this.admin != null) {
+						user_id = this.admin.id
+					} else {
+						user_id = 0
 					}
+					this.$api.my.userMemberAdd({
+						user_id,
+						page,
+					})
+					//增加票数
+					this.$api.my.userJoinVip({
+						source_type: 1,
+						source_id: this.sourceId
+					}).then(res => {
+						uni.setStorage({
+							key: 'is_vip',
+							data: 1,
+						});
+						this.is_vip = true
+					})
 				})
 			},
 			// 投票

+ 15 - 0
setting - 副本.js

xqd
@@ -0,0 +1,15 @@
+/**
+ * Created by JianJia.Zhou<jianjia.zhou> on 2022/3/18.
+ */
+const IS_DEV = process.env.NODE_ENV === 'development'
+// const URL = 'https://t9.9026.com'
+const URL = 'https://ihg.9026.com'
+
+module.exports = {
+  // 版本
+  VERSION: '0.0.1',
+  // API 接口URL
+  BASE_URL: IS_DEV ? 'https://t9.9026.com/api' : URL + '/api',
+  // API 接口URL
+  IMAGE_URL: IS_DEV ? 'https://t9.9026.com/static/image' : URL + '/static/image'
+}

+ 1 - 1
setting.js

xqd
@@ -1,7 +1,7 @@
 /**
  * Created by JianJia.Zhou<jianjia.zhou> on 2022/3/18.
  */
-const IS_DEV = process.env.NODE_ENV === 'development'
+const IS_DEV = process.env.NODE_ENV === 'development1'
 // const URL = 'https://t9.9026.com'
 const URL = 'https://ihg.9026.com'
 

+ 144 - 1
utils/tools.js

xqd
@@ -8,6 +8,149 @@ const toHttps = (url)=>{
 	return url;
 }
 
+/**
+ *	@param {
+		jump_type   		1.跳转H5 2.跳转新小程序 3.图片 4.跳转内部页面
+		jump_config   		string | stringify(object)
+		@param 其他参数		如:id,nav
+	}
+ * 注:jump_type,接口3和4有冲突所以写了兼容
+ * 注:图片跳转逻辑空缺
+ */
+const jump = ({jump_type, jump_config, ...params} = {})=>{
+	return new Promise((resolve, reject)=>{
+		if(!jump_type) reject(false);
+		jump_config = jump_config == undefined ? "" : jump_config;
+		if(jump_type == 1){
+			const nav =	Reflect.has(params, "nav") ?  `&nav=${params.nav}` : ``;
+			const url = `/pages/webview/webview?url=${jump_config+nav}`;
+			uni.navigateTo({
+				url: url,
+				success: () => {
+					resolve(true)
+				},
+				fail: _ => {
+					uni.reLaunch({
+						url: url,
+						fail:(err)=>{
+							reject(err)
+						}
+					})
+				}
+			});
+		}else if(jump_type == 2){
+			const {appid, path} = JSON.parse(jump_config);
+			wx.navigateToMiniProgram({
+				appId: `${appid}`,
+				path: `${path}`,
+				extraData: {
+					foo: 'bar'
+				},
+				// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
+				success:() => {
+					resolve(true)
+				},
+				fail:(err) => {
+					reject(err)
+				}
+			})
+		}else if(jump_type == 3){
+			if(jump_config.substr(0, 7) == '/pages/'){
+				jumpInner(jump_config, params)
+				.then(_=>{
+					resolve(true)
+				})
+				.catch(err=>{
+					reject(err)
+				})
+			}else{
+				//图片跳转
+				console.log("图片跳转逻辑空缺")
+			}
+		}else if(jump_type == 4){
+			jumpInner(jump_config, params)
+			.then(_=>{
+				resolve(true)
+			})
+			.catch(err=>{
+				reject(err)
+			})
+		}else{
+			reject('unkown error')
+		}
+	})
+}
+/**
+ * jumpy依赖函数
+ */
+const jumpInner = (url, params)=>{
+	const tabbarPageList = [
+		'pages/index/index',
+		'pages/map/map',
+		'pages/msg/msg',
+		'pages/my/my'
+	]
+	let paramsText = ``;
+	for(let [k, v] of Object.entries(params)){
+		paramsText +=`${k}=${v}&`
+	}
+	if(paramsText.length>0){
+		paramsText = paramsText.slice(0,paramsText.length-1);
+		url = url.indexOf("?") > -1 ? `${url}&${paramsText}` : `${url}?${paramsText}`;
+	}
+	let func = uni.switchTab;
+	const pages = getCurrentPages();
+	if(pages.length>0){
+		const {route} = pages[pages.length - 1];
+		tabbarPageList.includes(route)
+		func = tabbarPageList.includes(route) ? uni.reLaunch : uni.switchTab;
+	}
+	func = uni.reLaunch;
+	console.log(url, '跳转完整地址');
+	return new Promise((resolve,reject)=>{
+		uni.navigateTo({
+			url: url,
+			success:()=>{
+				resolve(true)
+			},
+			fail: _=>{
+				func({
+					url: url,
+					success:()=>{
+						resolve(true)
+					},
+					fail:(err)=>{
+						reject(err)
+					}
+				})
+			}
+		})
+	})
+}
+/**
+ * 跳转加入会员小程序
+ */
+const jumpJoinVip = () => {
+	return new Promise((resolve, reject)=>{
+		wx.navigateToMiniProgram({
+			appId: 'wx255b58f0992b3c53', //appid
+			path: 'newUIMain/enrollment/enrollment', //path
+			extraData: { //参数
+				foo: 'bar'
+			},
+			// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
+			success(res) {
+				resolve(res)
+				// 打开成功
+			},
+			fail(e) {
+				reject(e)
+			}
+		})
+	})
+}
 export default {
-	toHttps
+	toHttps,
+	jump,
+	jumpJoinVip
 }