hmp 4 年之前
父節點
當前提交
4ef5bad623
共有 6 個文件被更改,包括 106 次插入106 次删除
  1. 2 2
      assets/http/config.js
  2. 4 0
      main.js
  3. 5 0
      package-lock.json
  4. 33 48
      pages/index/home.vue
  5. 46 43
      store/index.js
  6. 16 13
      utils/jweixin.js

+ 2 - 2
assets/http/config.js

@@ -1,7 +1,7 @@
 let config = {}
 
-config.baseURL = 'http://192.168.1.168:2888'
-// config.baseURL = 'https://vote.guosen-fumao.cn/api'
+// config.baseURL = 'http://192.168.1.168:2888'
+config.baseURL = 'https://vote.guosen-fumao.cn/api'
 //是否需要获取手机号
 config.isAuthPhone = true
 config.transformDomains = 'https://m.changyoyo.com'

+ 4 - 0
main.js

@@ -30,6 +30,10 @@ import pointAuth from '@/components/alert/pointAuth.vue'
 Vue.component('pointAuth',pointAuth)
 
 // util begin
+// #ifdef H5
+import wx from "@/utils/jweixin.js"
+Vue.prototype.$shareConfig = wx
+// #endif
 //缓存
 import simpleCache from "@/utils/cache.js"
 Vue.prototype.$cache = simpleCache

+ 5 - 0
package-lock.json

@@ -9,6 +9,11 @@
 			"resolved": "https://registry.npmmirror.com/@dcloudio/types/download/@dcloudio/types-2.5.13.tgz",
 			"integrity": "sha1-VNCLDMplKgiEGLr2sS0864rITHA="
 		},
+		"jweixin-module": {
+			"version": "1.6.0",
+			"resolved": "https://registry.npm.taobao.org/jweixin-module/download/jweixin-module-1.6.0.tgz",
+			"integrity": "sha1-Sn6mFAg+PJw/SeL9wruILPpY380="
+		},
 		"luch-request": {
 			"version": "3.0.7",
 			"resolved": "https://registry.nlark.com/luch-request/download/luch-request-3.0.7.tgz",

+ 33 - 48
pages/index/home.vue

@@ -1,7 +1,7 @@
 <template>
 	<view :style="vuex_skin">
 		<!-- #ifdef MP-WEIXIN -->
-		<u-navbar title-color="#000000"  :is-back="fasle" title="首页"></u-navbar>
+		<u-navbar title-color="#000000" :is-back="fasle" title="首页"></u-navbar>
 		<!-- #endif -->
 		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback"
 			@up="upCallback">
@@ -11,10 +11,10 @@
 			<view style="padding: 30rpx 30rpx 10rpx;">
 				<u-swiper :list="swiperList" border-radius="12" name="url" mode="rect" height="300"></u-swiper>
 			</view>
-			
+
 			<view class="">
 				<view class="cu-list grid  no-border" :class="gridClass" style="border-radius:20rpx ;">
-					<view class="cu-item" @click.stop="jump(item)"  v-for="(item,index) in gridList" :key="index">
+					<view class="cu-item" @click.stop="jump(item)" v-for="(item,index) in gridList" :key="index">
 						<view class="grid-icon">
 							<image style="width: 88rpx;height: 88rpx;" :src="item.icon" />
 						</view>
@@ -88,10 +88,7 @@
 <script>
 	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
 	import util from "@/utils/util.js";
-	// #ifdef H5
-	import jssdk from "@/utils/jweixin.js"
-	// #endif
-	
+
 	export default {
 		mixins: [MescrollMixin],
 		data() {
@@ -119,14 +116,14 @@
 				//轮播图
 				swiperList: [],
 				//菜单
-				gridClass:'',
+				gridClass: '',
 				gridList: [],
-				keyword:'',
+				keyword: '',
 				noticeContent: [],
 				//活动详情
 				activeInfo: {},
 				//参赛的路径
-				applyUrl:""
+				applyUrl: ""
 			};
 		},
 		onLoad(options) {
@@ -139,42 +136,28 @@
 			this.canReset = true;
 		},
 		methods: {
-			/**
-			 * 获取H5分享数据
-			 */
-			async getWxShareData(shareParam){
-				//获取当前url传递给后台获取授权和签名信息
-				let url = encodeURIComponent(window.location.href.split('#')[0])
-				let params={
-					url: url
-				}
-				
-				this.$api.wxApp.getWxShareData(params).then(res=>{
-					jssdk.H5Share(res.data.data, shareParam);
-				})
-			},
 			/**
 			 * 获取活动详情
 			 */
-			async activeDetail(){
-				let params={
+			async activeDetail() {
+				let params = {
 					id: this.activeId
 				}
-				this.$api.activerecord.detail(params).then(res=>{
+				this.$api.activerecord.detail(params).then(res => {
 					this.activeInfo = res.data.data;
 				})
 			},
 			/**
 			 * 获取通知公告
 			 */
-			async getNotice(){
-				let params={
-					activeId:this.activeId,
-					title:'活动通知'
+			async getNotice() {
+				let params = {
+					activeId: this.activeId,
+					title: '活动通知'
 				}
-				this.$api.notice.list(params).then(res=>{
-					let notices=res.data.data.records
-					if (this.$isNotEmpty(notices)&&this.$isNotEmpty(notices[0].content)) {
+				this.$api.notice.list(params).then(res => {
+					let notices = res.data.data.records
+					if (this.$isNotEmpty(notices) && this.$isNotEmpty(notices[0].content)) {
 						this.noticeContent.push(util.formatHtml(notices[0].content))
 					}
 				})
@@ -212,8 +195,10 @@
 				}
 				let activeSetting = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data);
 				// #ifdef H5
-				if(this.$isNotEmpty(activeSetting.shareParam)){
-					this.getWxShareData(activeSetting.shareParam);
+				if (this.$isNotEmpty(activeSetting.shareParam)) {
+					let shareParam=activeSetting.shareParam
+					shareParam.link=window.location.href
+					this.$shareConfig.H5Share(shareParam)
 				}
 				// #endif
 				activeSetting.defaultActiveId = this.activeId
@@ -241,12 +226,12 @@
 				//获取排行榜
 				this.mescroll.resetUpScroll();
 				//获取轮播图
-				let gridList=this.vuex_active_setting.functionItemList
+				let gridList = this.vuex_active_setting.functionItemList
 				if (this.$isNotEmpty(gridList)) {
-					this.gridList = gridList.filter(item=>item.show == 1)
-					this.gridClass='col-'+this.gridList.length
+					this.gridList = gridList.filter(item => item.show == 1)
+					this.gridClass = 'col-' + this.gridList.length
 				}
-				console.log(gridList,"gridList");
+				console.log(gridList, "gridList");
 				this.swiperList = this.vuex_active_setting.indexImageList
 			},
 			jump(item) {
@@ -255,7 +240,7 @@
 				}
 				if (item.name == '报名参赛') {
 					//登录后才可以参赛
-					this.applyUrl=`${item.path}?activeId=${this.activeId}&activeType=${this.activeInfo.type}`
+					this.applyUrl = `${item.path}?activeId=${this.activeId}&activeType=${this.activeInfo.type}`
 					this.login()
 					return;
 				}
@@ -263,18 +248,18 @@
 					url: item.path
 				})
 			},
-			init(){
+			init() {
 				this.goApply()
 			},
-			goApply(){
+			goApply() {
 				let nowTime = new Date().getTime();
-				let startTime=this.$dateTime.getTime(this.activeInfo.startTime)
-				let endTime=this.$dateTime.getTime(this.activeInfo.endTime)
-				if(nowTime < startTime){
+				let startTime = this.$dateTime.getTime(this.activeInfo.startTime)
+				let endTime = this.$dateTime.getTime(this.activeInfo.endTime)
+				if (nowTime < startTime) {
 					this.$refs.toast.info("活动未开始");
-				}else if(nowTime > endTime){
+				} else if (nowTime > endTime) {
 					this.$refs.toast.info("活动已结束");
-				}else{
+				} else {
 					uni.navigateTo({
 						url: this.applyUrl
 					})

+ 46 - 43
store/index.js

@@ -1,26 +1,29 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
 import config from '../assets/http/config.js'
-import { api } from '../assets/http/api.js'
+import {
+	api
+} from '../assets/http/api.js'
 Vue.use(Vuex)
 
 let lifeData = {};
 
-try{
+try {
 	// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
 	lifeData = uni.getStorageSync('lifeData');
-}catch(e){
-	
+} catch (e) {
+
 }
 
 // 需要永久存储,且下次APP启动需要取出的,在state中的变量名
-let saveStateKeys = ['vuex_audit','vuex_userId','vuex_phone','vuex_skin',
-			'vuex_theme','vuex_active_setting','vuex_isCMCC'];
+let saveStateKeys = ['vuex_audit', 'vuex_userId', 'vuex_phone', 'vuex_skin',
+	'vuex_theme', 'vuex_active_setting', 'vuex_isCMCC'
+];
 
 // 保存变量到本地存储中
-const saveLifeData = function(key, value){
+const saveLifeData = function(key, value) {
 	// 判断变量名是否在需要存储的数组中
-	if(saveStateKeys.indexOf(key) != -1) {
+	if (saveStateKeys.indexOf(key) != -1) {
 		// 获取本地存储的lifeData对象,将变量添加到对象中
 		let tmp = uni.getStorageSync('lifeData');
 		// 第一次打开APP,不存在lifeData变量,故放一个{}空对象
@@ -32,41 +35,41 @@ const saveLifeData = function(key, value){
 }
 
 const store = new Vuex.Store({
-		// 下面这些值仅为示例,使用过程中请删除
-		state: {
-			// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
-			// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
-			vuex_audit: lifeData.vuex_audit ? lifeData.vuex_audit : 0,
-			vuex_userId: lifeData.vuex_userId ? lifeData.vuex_userId : null,
-			vuex_phone: lifeData.vuex_phone ? lifeData.vuex_phone : null,
-			vuex_skin: lifeData.vuex_skin ? lifeData.vuex_skin : config.themeRed.skin,
-			vuex_theme: lifeData.vuex_theme ? lifeData.vuex_theme : config.themeRed.theme,
-			vuex_active_setting: lifeData.vuex_active_setting ? lifeData.vuex_active_setting :  {},
-			vuex_isCMCC: lifeData.vuex_isCMCC ? lifeData.vuex_isCMCC :  false,
-		},
-	
-		mutations: {
-			$uStore(state, payload) {
-				// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
-				let nameArr = payload.name.split('.');
-				let saveKey = '';
-				let len = nameArr.length;
-				if(nameArr.length >= 2) {
-					let obj = state[nameArr[0]];
-					for(let i = 1; i < len - 1; i ++) {
-						obj = obj[nameArr[i]];
-					}
-					obj[nameArr[len - 1]] = payload.value;
-					saveKey = nameArr[0];
-				} else {
-					// 单层级变量,在state就是一个普通变量的情况
-					state[payload.name] = payload.value;
-					saveKey = payload.name;
+	// 下面这些值仅为示例,使用过程中请删除
+	state: {
+		// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
+		// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
+		vuex_audit: lifeData.vuex_audit ? lifeData.vuex_audit : 0,
+		vuex_userId: lifeData.vuex_userId ? lifeData.vuex_userId : null,
+		vuex_phone: lifeData.vuex_phone ? lifeData.vuex_phone : null,
+		vuex_skin: lifeData.vuex_skin ? lifeData.vuex_skin : config.themeRed.skin,
+		vuex_theme: lifeData.vuex_theme ? lifeData.vuex_theme : config.themeRed.theme,
+		vuex_active_setting: lifeData.vuex_active_setting ? lifeData.vuex_active_setting : {},
+		vuex_isCMCC: lifeData.vuex_isCMCC ? lifeData.vuex_isCMCC : false,
+	},
+
+	mutations: {
+		$uStore(state, payload) {
+			// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
+			let nameArr = payload.name.split('.');
+			let saveKey = '';
+			let len = nameArr.length;
+			if (nameArr.length >= 2) {
+				let obj = state[nameArr[0]];
+				for (let i = 1; i < len - 1; i++) {
+					obj = obj[nameArr[i]];
 				}
-				// 保存变量到本地,见顶部函数定义
-				saveLifeData(saveKey, state[saveKey])
+				obj[nameArr[len - 1]] = payload.value;
+				saveKey = nameArr[0];
+			} else {
+				// 单层级变量,在state就是一个普通变量的情况
+				state[payload.name] = payload.value;
+				saveKey = payload.name;
 			}
+			// 保存变量到本地,见顶部函数定义
+			saveLifeData(saveKey, state[saveKey])
 		}
-	})
-	
-export default store
+	}
+})
+
+export default store

+ 16 - 13
utils/jweixin.js

@@ -1,10 +1,12 @@
 let wx = {}
+import {api} from "../assets/http/api.js"
 let jweixin = require('jweixin-module');
-
+let url = encodeURIComponent(window.location.href.split('#')[0])
 /**
  * JS-SDK
  */
-wx.H5Share = (shareData, shareParam) => {
+wx.H5Share = async (shareParam) => {
+	let shareData=(await api.wxApp.getWxShareData({url})).data.data
 	//通过微信config接口注入配置
 	jweixin.config({
 		debug: false, //调试模式
@@ -17,18 +19,19 @@ wx.H5Share = (shareData, shareParam) => {
 			'updateAppMessageShareData'
 		] //必填,需要使用的JS接口列表
 	})
-	let shareContent = { //自定义分享内容
-		share: {
-			imgUrl: shareParam.imgUrl, //分享图标
-			desc: shareParam.desc, //分享介绍
-			title: shareParam.title, //分享标题
-			link: window.location.href, //分享网址
-			success: function(res) {}
-		}
-	}
 	jweixin.ready(function() {
-		// jweixin.updateTimelineShareData(shareContent.share) //分享微信朋友圈
-		jweixin.updateAppMessageShareData(shareContent.share) //分享微信好友
+		jweixin.updateTimelineShareData({
+			...shareParam,
+			success: function() {
+				console.log("配置分享朋友圈成功");
+			}
+		})
+		jweixin.updateAppMessageShareData({
+			...shareParam,
+			success: function() {
+				console.log("配置分享微信好友成功");
+			}
+		})
 	})		
 }