diff --git a/common/mixins/wxshare.mixin.js b/common/mixins/wxshare.mixin.js
new file mode 100644
index 0000000..40126d9
--- /dev/null
+++ b/common/mixins/wxshare.mixin.js
@@ -0,0 +1,66 @@
+// 微信分享配置
+import haloConfig from '@/config/halo.config.js'
+import { jsonToUrlParams2 } from '@/utils/url.params.js'
+export const haloWxShareMixin = {
+ data() {
+ return {
+ haloWxShareData: {
+ ...haloConfig.wxShareConfig
+ },
+ }
+ },
+
+ //#ifdef MP-WEIXIN
+ onShareAppMessage(res) {
+ return {
+ ...this.haloWxShareData,
+ success: res => {}
+ }
+ },
+ //#endif
+ /* 分享到微信好友 */
+ onShareAppMessage(res) {
+ const promise = new Promise(resolve => {
+ setTimeout(() => {
+ resolve({
+ title: this.haloWxShareData.title,
+ path: this.haloWxShareData.path,
+ })
+ }, 2000)
+ })
+ return {
+ title: this.haloWxShareData.title,
+ path: '',
+ promise
+ }
+ },
+
+ // 分享到朋友圈-这里封装不够,在页面还要声明一次,否则是拿不到参数的,被分享者在朋友圈打开链接是空的
+ onShareTimeline: function() {
+ return {
+ title: this.haloWxShareData.title,
+ query: {},
+ imageUrl: this.haloWxShareData.imageUrl,
+ }
+ },
+ methods: {
+ // 设置分享信息(需要在页面调用)
+ fnSetWxShareConfig(config = {}) {
+ let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
+ let currentRoute = currentRoutes[currentRoutes.length - 1].route; //获取当前页面路由(分销思路,分享者点开使用的小程序将获取到分享者的id)
+ let sharePath = currentRoutes
+ if (config.params) {
+ const URLParams = config.params ? jsonToUrlParams2(config.params) : {};
+ sharePath += URLParams
+ }
+ let _config = Object.assign({}, {
+ path: sharePath,
+ copyLink: haloConfig.apiUrl,
+ query: {}
+ }, config)
+
+ uni.$tm.vx.commit('setWxShare', _config);
+ this.haloWxShareData = _config;
+ }
+ }
+}
diff --git a/config/halo.config.template.js b/config/halo.config.template.js
index 1b2df78..28853a0 100644
--- a/config/halo.config.template.js
+++ b/config/halo.config.template.js
@@ -122,8 +122,8 @@ export default {
title: '', // 小程序分享标题[非必填]
desc: '', // 小程序分享描述[非必填]
imageUrl: '', // 小程序分享时候图片地址[非必填]
- path: '/pages/start/start', // 分享路径[非必填] - 基本不需要修改
- copyLink: '/pages/start/start', // 复制链接[非必填] - 基本不需要修改
+ path: '/pages/index/index', // 分享路径[非必填] - 基本不需要修改
+ copyLink: '/pages/index/index', // 复制链接[非必填] - 基本不需要修改
query: {}, // 分享参数[非必填] - 基本不需要填写
},
diff --git a/pages/tabbar/about/about.vue b/pages/tabbar/about/about.vue
index e56f978..abe1219 100644
--- a/pages/tabbar/about/about.vue
+++ b/pages/tabbar/about/about.vue
@@ -5,7 +5,9 @@
{{ bloggerInfo.nickname }}
- {{ bloggerInfo.description || '这个博主很懒,竟然没写介绍~' }}
+
+ {{ bloggerInfo.description || '这个博主很懒,竟然没写介绍~' }}
+
@@ -17,19 +19,34 @@
-
+
文章总数
-
+
分类总数
-
+
标签总数
@@ -37,19 +54,34 @@
-
+
评论数量
-
+
点赞数量
-
+
访客数量
@@ -60,7 +92,12 @@
-
+
{{ nav.text }}
@@ -80,7 +117,9 @@
@click="fnOnNav(nav)"
>
-
+
{{ nav.rightText }}
@@ -88,7 +127,9 @@
- 「 2022 uni-halo 丨 开源项目@小莫唐尼 」
+
+ 「 2022 uni-halo 丨 开源项目@小莫唐尼 」
+
@@ -97,17 +138,35 @@
{{ bloggerInfo.nickname }}
- 前端摸鱼大师
- 一个爱凑热闹的、喜欢捣鼓前端的博主。
+
+ 前端摸鱼大师
+
+
+ 一个爱凑热闹的、喜欢捣鼓前端的博主。
+
爱好:摸鱼、打游戏、听音乐、逛B站
- 如果不是在空闲着的时候就能挣到钱,那就不算摸鱼!
+
+ 如果不是在空闲着的时候就能挣到钱,那就不算摸鱼!
+
精选图片
-
-
-
+
+
+
@@ -386,7 +445,8 @@ export default {
})
.then(res => {
uni.clearStorageSync();
- this.navList.find(x => x.key == 'cache').rightText = uni.getStorageInfoSync().currentSize + 'KB';
+ this.navList.find(x => x.key == 'cache').rightText =
+ uni.getStorageInfoSync().currentSize + 'KB';
})
.catch(err => {});
break;
@@ -417,6 +477,18 @@ export default {
// 快捷导航页面跳转
fnToNavPage(item) {
+ // 判断是内置页面还是网页
+ if (this.$utils.checkIsUrl(item.path)) {
+ uni.navigateTo({
+ url:
+ '/pagesC/website/website?data=' +
+ JSON.stringify({
+ title: item.text || this.$haloConfig.title,
+ url: item.path
+ })
+ });
+ return;
+ }
switch (item.type) {
case 'tabbar':
uni.switchTab({
diff --git a/pagesA/article-detail/article-detail.vue b/pagesA/article-detail/article-detail.vue
index 64a66d4..57feda7 100644
--- a/pagesA/article-detail/article-detail.vue
+++ b/pagesA/article-detail/article-detail.vue
@@ -12,10 +12,14 @@
博主:{{ author.nickname }}
- 时间:{{ { d: result.createTime, f: 'yyyy年MM月dd日 星期w' } | formatTime }}
+
+ 时间:{{ { d: result.createTime, f: 'yyyy年MM月dd日 星期w' } | formatTime }}
+
-
+
+
+
{{ result.visits }}
@@ -42,14 +46,27 @@
分类:
未选择分类
- {{ item.name }}
+
+ {{ item.name }}
+
标签:
未选择标签
-
+
{{ item.name }}
@@ -96,21 +113,39 @@
广告
-
+
{{ haloAdConfig.articleDetail.custom.title }}
{{ haloAdConfig.articleDetail.custom.content }}
- 立即查看
+
+ 立即查看
+
版权声明
-
- 版权归属:{{ copyright.author }}
- 版权说明:{{ copyright.description }}
- 侵权处理:{{ copyright.violation }}
+
+
+ 版权归属:{{ copyright.author }}
+
+
+ 版权说明:{{ copyright.description }}
+
+
+ 侵权处理:{{ copyright.violation }}
+
@@ -129,8 +164,19 @@
-
-
+
+
@@ -138,7 +184,13 @@
评论详情
-
+
@@ -149,7 +201,14 @@
- 刷新试试
+
+ 刷新试试
+
@@ -185,9 +244,15 @@
- 保存到相册
- 分享给好友
- 关 闭
+
+ 保存到相册
+
+
+ 分享给好友
+
+
+ 关 闭
+
@@ -210,6 +275,8 @@ import commentItem from '@/components/comment-item/comment-item.vue';
import rCanvas from '@/components/r-canvas/r-canvas.vue';
import barrage from '@/components/barrage/barrage.vue';
+
+import { haloWxShareMixin } from '@/common/mixins/wxshare.mixin.js';
export default {
components: {
tmSkeleton,
@@ -223,6 +290,7 @@ export default {
rCanvas,
barrage
},
+ mixins: [haloWxShareMixin],
data() {
return {
loading: 'loading',
@@ -304,7 +372,14 @@ export default {
this.result = res.data;
this.fnSetPageTitle('文章详情');
this.loading = 'success';
- this.fnSetWxShareInfo();
+ this.fnSetWxShareConfig({
+ title: this.result.title,
+ desc: this.result.summary,
+ imageUrl: this.$utils.checkThumbnailUrl(this.result.thumbnail),
+ path: `/pagesA/article-detail/article-detail?articleId=${this.queryParams.articleId}`,
+ copyLink: this.$haloConfig.apiUrl,
+ query: {}
+ });
})
.catch(err => {
this.loading = 'error';
@@ -314,19 +389,7 @@ export default {
uni.stopPullDownRefresh();
});
},
- fnSetWxShareInfo() {
- // #ifdef MP-WEIXIN
- uni.$tm.vx.commit('setWxShare', {
- title: this.result.title,
- desc: this.result.summary,
- // imageUrl: this.poster.res.tempFilePath,
- imageUrl: this.$utils.checkThumbnailUrl(this.result.thumbnail),
- path: `/pagesA/article-detail/article-detail?articleId=${this.queryParams.articleId}`,
- copyLink: this.$haloConfig.apiUrl,
- query: {}
- });
- // #endif
- },
+
// 浮动按钮点击
fnOnFlotButtonChange(index) {
switch (index) {
diff --git a/utils/url.params.js b/utils/url.params.js
new file mode 100644
index 0000000..8c1165c
--- /dev/null
+++ b/utils/url.params.js
@@ -0,0 +1,52 @@
+/**
+ * 对象转换为url参数形式
+ * @param {Object} param 将要转换为URL参数的字符串对象
+ * @param {String} key URL 参数字符串的前缀
+ * @param {Boolean} encode 是否进行URL编码,默认为true
+ * @return {String} URL参数字符串
+ */
+export function jsonToUrlParams(param, key, encode) {
+ if (param == null) return '';
+ let paramStr = '';
+ let t = typeof(param);
+ if (t == 'string' || t == 'number' || t == 'boolean') {
+ paramStr += '&' + key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param);
+ } else {
+ for (var i in param) {
+ var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
+ paramStr += jsonToUrlParams(param[i], k, encode);
+ }
+ }
+ return paramStr;
+}
+
+
+/**
+ * @param {Array} actual
+ * @returns {Array}
+ */
+export function cleanArray(actual) {
+ const newArray = []
+ for (let i = 0; i < actual.length; i++) {
+ if (actual[i]) {
+ newArray.push(actual[i])
+ }
+ }
+ return newArray
+}
+
+
+/**
+ * json对象转Url参数2
+ * @param {Object} json
+ * @returns {Array}
+ */
+export function jsonToUrlParams2(json) {
+ if (!json) return ''
+ return cleanArray(
+ Object.keys(json).map(key => {
+ if (json[key] === undefined) return ''
+ return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
+ })
+ ).join('&')
+}