From 4b56792e6306658067f0229c3da170805d9cb49f Mon Sep 17 00:00:00 2001
From: Gaoxs <704041637@qq.com>
Date: Tue, 15 Sep 2020 10:42:23 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=AE=E6=92=AD=E5=9B=BE?=
=?UTF-8?q?=E5=8D=A1=E9=A1=BF=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config/index.js | 5 +-
libs/wechat.js | 14 ++-
main.js | 24 ++++-
pages/Loading/index.vue | 180 +++++++++++++++++--------------
pages/home/components/Banner.vue | 63 ++++-------
pages/home/index.vue | 3 +-
utils/index.js | 95 ++++++++++------
utils/store/cookie.js | 1 +
剩余问题.js | 32 ------
9 files changed, 229 insertions(+), 188 deletions(-)
delete mode 100644 剩余问题.js
diff --git a/config/index.js b/config/index.js
index b46828a..c54667e 100644
--- a/config/index.js
+++ b/config/index.js
@@ -1,7 +1,8 @@
// export const VUE_APP_API_URL = 'http://natapp.xinxintuan.co/api';
-// export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api';
+export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api';
// export const VUE_APP_API_URL = 'http://192.168.31.223:8008/api';
-export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
+// export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
+// export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
export const VUE_APP_RESOURCES_URL = 'https://wx.yixiang.co/static';
diff --git a/libs/wechat.js b/libs/wechat.js
index da1849a..c91baad 100644
--- a/libs/wechat.js
+++ b/libs/wechat.js
@@ -147,7 +147,8 @@ export function auth(code) {
console.log('获取微信授权')
return new Promise((resolve, reject) => {
let loginType = cookie.get(LOGINTYPE);
- wechatAuth(code, parseInt(cookie.get("spread")), loginType)
+ let spread = cookie.get(spread);
+ wechatAuth(code, spread, loginType)
.then(({ data }) => {
console.log(data)
const expires_time = dayjs(data.expires_time);
@@ -171,8 +172,15 @@ export function toAuth() {
}
function getAuthUrl(appId) {
- const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index`);
- // const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index`encodeURIComponent(encodeURIComponent(cookie.has(BACK_URL)? cookie.get(BACK_URL): location.pathname + location.search)));
+
+ // const redirect_uri = encodeURIComponent(window.location.href);
+ // const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index`);
+
+ // #ifdef H5
+ // #endif
+
+
+ const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index?path=${encodeURIComponent(window.location.href)}`);
// const redirect_uri = encodeURIComponent(`${window.location.origin}${window.location.pathname}`)
// const redirect_uri = encodeURIComponent(`${location.origin}`)
cookie.remove(BACK_URL);
diff --git a/main.js b/main.js
index 07e1e9d..b344a5a 100644
--- a/main.js
+++ b/main.js
@@ -23,7 +23,8 @@ import cookie from "@/utils/store/cookie";
import {
parseRoute,
- _router
+ _router,
+ parseQuery
} from "@/utils";
import {
VUE_APP_RESOURCES_URL,
@@ -102,6 +103,27 @@ import {
import { isWeixin } from '@/utils'
+
+const CACHE_KEY = "clear_0.0.1";
+
+if (!cookie.has(CACHE_KEY)) {
+ cookie.clearAll();
+ cookie.set(CACHE_KEY, 1);
+}
+
+var urlSpread = parseQuery()["spread"];
+
+if (urlSpread !== undefined) {
+ var spread = cookie.get("spread");
+ urlSpread = parseInt(urlSpread);
+ if (!Number.isNaN(urlSpread) && spread !== urlSpread) {
+ cookie.set("spread", urlSpread || 0);
+ } else if (spread === 0 || typeof spread !== "number") {
+ cookie.set("spread", urlSpread || 0);
+ }
+}
+
+
// 判断是否是微信浏览器
if (isWeixin()) {
Vue.prototype.$deviceType = 'weixin'
diff --git a/pages/Loading/index.vue b/pages/Loading/index.vue
index 0959adc..4d90a5b 100644
--- a/pages/Loading/index.vue
+++ b/pages/Loading/index.vue
@@ -1,97 +1,119 @@
-
+
diff --git a/pages/home/components/Banner.vue b/pages/home/components/Banner.vue
index 8146a73..90a3731 100644
--- a/pages/home/components/Banner.vue
+++ b/pages/home/components/Banner.vue
@@ -2,14 +2,14 @@
-
+
+ v-for="(dot, index) in detail.length" :key="index">
@@ -22,43 +22,28 @@
return {
swiperCurrent: 0, //轮播下标
webviewId: 0,
- bgcolorAry: [],
- list: []
};
},
props: {
- banner: {
+ detail: {
type: Array,
default: []
}
},
created: async function () {
await this.doColorThief();
-
- },
- async mounted() {
-
},
computed: {},
- watch: {
- banner(next) {
- this.list = next;
- this.doColorThief()
- }
- },
methods: {
async doColorThief() {
let that = this;
// 获取轮播图
- let item = this.list[this.swiperCurrent];
- if(!item){
- return
- }
+ let item = this.detail[this.swiperCurrent];
// 获取轮播图颜色
- let bgcolor = this.bgcolorAry[this.swiperCurrent];
+ let bgcolor = item.bgcolor;
// 颜色不存在
- if (!bgcolor) {
- let ctx = uni.createCanvasContext('colorThief', that.$scope);
+ if (bgcolor === '') {
+ let ctx = uni.createCanvasContext('colorThief', that);
if (0 === that.webviewId || ctx.webviewId === that.webviewId) {
that.webviewId = ctx.webviewId;
uni.getImageInfo({
@@ -67,26 +52,22 @@
ctx.drawImage(image.path, 0, 0, image.width, image.height);
ctx.draw(true, function (e) {
uni.canvasGetImageData({
- canvasId: 'colorThief',
- x: 0,
- y: 0,
- width: parseInt(image.width),
- height: parseInt(image.height),
- success(res) {
- let newBgcolor = colorThief(res.data)
- .color()
- .getHex();
- that.$set(that.bgcolorAry, that
- .swiperCurrent,
- newBgcolor);
- that.$emit('getbgcolor', newBgcolor);
+ canvasId: 'colorThief',
+ x: 0,
+ y: 0,
+ width: parseInt(image.width),
+ height: parseInt(image.height),
+ success(res) {
+ let bgcolor = colorThief(res.data)
+ .color()
+ .getHex();
+ that.$set(item, 'bgcolor', bgcolor);
+ that.$emit('getbgcolor', bgcolor);
+ }
},
- fail: function (error) {
- }
- }, that.$scope);
+ that
+ );
});
- },
- fail: function (error) {
}
});
}
@@ -98,6 +79,8 @@
swiperChange(e) {
this.swiperCurrent = e.detail.current;
this.doColorThief();
+ let bgcolor = this.detail[this.swiperCurrent].bgcolor;
+ this.$emit('getbgcolor', bgcolor);
},
// 路由跳转
diff --git a/pages/home/index.vue b/pages/home/index.vue
index 5956cd8..0583c5d 100644
--- a/pages/home/index.vue
+++ b/pages/home/index.vue
@@ -22,7 +22,7 @@
-
+
@@ -215,6 +215,7 @@
});
getHomeData().then(res => {
that.logoUrl = res.data.logoUrl;
+ res.data.banner.map(item => item.bgcolor = '')
that.$set(that, 'banner', res.data.banner);
that.$set(that, 'menus', res.data.menus);
that.$set(that, 'roll', res.data.roll);
diff --git a/utils/index.js b/utils/index.js
index eaf884b..3de2e27 100644
--- a/utils/index.js
+++ b/utils/index.js
@@ -38,27 +38,27 @@ export function dataFormat(time, option) {
return timeStr
}
}
- // 年月日,时分秒
- // "YYYY-mm-dd HH:MM"
-export function dateFormatL(fmt, date) {
- let ret;
- const opt = {
- "Y+": date.getFullYear().toString(), // 年
- "m+": (date.getMonth() + 1).toString(), // 月
- "d+": date.getDate().toString(), // 日
- "H+": date.getHours().toString(), // 时
- "M+": date.getMinutes().toString(), // 分
- "S+": date.getSeconds().toString() // 秒
- // 有其他格式化字符需求可以继续添加,必须转化成字符串
+// 年月日,时分秒
+// "YYYY-mm-dd HH:MM"
+export function dateFormatL(fmt, date) {
+ let ret;
+ const opt = {
+ "Y+": date.getFullYear().toString(), // 年
+ "m+": (date.getMonth() + 1).toString(), // 月
+ "d+": date.getDate().toString(), // 日
+ "H+": date.getHours().toString(), // 时
+ "M+": date.getMinutes().toString(), // 分
+ "S+": date.getSeconds().toString() // 秒
+ // 有其他格式化字符需求可以继续添加,必须转化成字符串
+ };
+ for (let k in opt) {
+ ret = new RegExp("(" + k + ")").exec(fmt);
+ if (ret) {
+ fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
};
- for (let k in opt) {
- ret = new RegExp("(" + k + ")").exec(fmt);
- if (ret) {
- fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
- };
- };
- return fmt;
- }
+ };
+ return fmt;
+}
export function dateFormatT(time) {
time = +time * 1000;
const d = new Date(time);
@@ -82,18 +82,50 @@ export function isType(arg, type) {
}
export function isWeixin() {
- if(navigator&&navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1){
+ if (navigator && navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1) {
return true
}
return false
}
export function parseQuery() {
+
+ // #ifdef H5
+
+ const res = {};
+
+ const query = (location.href.split("?")[1] || "")
+ .trim()
+ .replace(/^(\?|#|&)/, "");
+
+ if (!query) {
+ return res;
+ }
+
+ query.split("&").forEach(param => {
+ const parts = param.replace(/\+/g, " ").split("=");
+ const key = decodeURIComponent(parts.shift());
+ const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
+
+ if (res[key] === undefined) {
+ res[key] = val;
+ } else if (Array.isArray(res[key])) {
+ res[key].push(val);
+ } else {
+ res[key] = [res[key], val];
+ }
+ });
+ // #endif
+
+ // #ifdef MP-WEIXIN
+
var pages = getCurrentPages() //获取加载的页面
var currentPage = pages[pages.length - 1] //获取当前页面的对象
var url = currentPage.route //当前页面url
- var options = currentPage.options //如果要获取url中所带的参数可以查看options
- return options
+ var res = currentPage.options //如果要获取url中所带的参数可以查看options
+ // #endif
+
+ return res
}
/*获取当前页url*/
@@ -110,7 +142,6 @@ export function getCurrentPageUrlWithArgs() {
var currentPage = pages[pages.length - 1] //获取当前页面的对象
var url = currentPage.route //当前页面url
var options = currentPage.options //如果要获取url中所带的参数可以查看options
-
//拼接url的参数
var urlWithArgs = url + '?'
for (var key in options) {
@@ -118,7 +149,6 @@ export function getCurrentPageUrlWithArgs() {
urlWithArgs += key + '=' + value + '&'
}
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
-
return urlWithArgs
}
@@ -505,6 +535,7 @@ export function routerPermissions(url, type) {
if (!path) {
path = '/' + getCurrentPageUrlWithArgs()
}
+ console.log(Vue.prototype.$deviceType)
if (Vue.prototype.$deviceType == 'routine') {
console.log('————————')
console.log('当前是微信小程序,开始处理小程序登录方法')
@@ -577,6 +608,13 @@ export function routerPermissions(url, type) {
})
cookie.set('redirect', path)
})
+ // } else if (Vue.prototype.$deviceType == 'weixin') {
+ // wechat().then(() => oAuth());
+ // if (!type) {
+ // push({
+ // path: url,
+ // })
+ // }
} else {
// 如果不是小程序跳转到登录页
console.log('当前无法自动登录,开始处理登录方法')
@@ -681,7 +719,6 @@ export function handleQrCode() {
export function handleUrlParam(path) {
console.log(path)
-
var url = path.split("?")[1]; //获取url中"?"符后的字串
console.log(url)
var theRequest = new Object();
@@ -819,10 +856,9 @@ export const handleLoginFailure = () => {
console.log('————————')
store.commit("updateAuthorizationPage", true);
let path = '/' + getCurrentPageUrlWithArgs()
- console.log("getCurrentPageUrl",getCurrentPageUrl());
+ console.log("getCurrentPageUrl", getCurrentPageUrl());
//判断小程序转发分享商品详情进来的
if (getCurrentPageUrl() == 'pages/shop/GoodsCon/index' && handleUrlParam(path) && !handleQrCode()) {
- debugger;
console.log('————————')
console.log('判断小程序转发分享商品详情进来的')
console.log(' handleUrlParam()', handleUrlParam(path))
@@ -894,7 +930,7 @@ export const handleLoginFailure = () => {
}
// 判断是不是转发分享的砍价海报进来的
- if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleUrlParam(path) && !handleQrCode()) {
+ if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleUrlParam(path) && !handleQrCode()) {
console.log('————————')
console.log('判断是不是转发分享的砍价海报进来的')
console.log('————————')
@@ -967,7 +1003,6 @@ export const handleLoginFailure = () => {
}
if (getCurrentPageUrl() == 'pages/shop/GoodsCon/index' && handleQrCode()) {
- debugger;
console.log('————————')
console.log('是扫描的商品详情')
console.log('————————')
diff --git a/utils/store/cookie.js b/utils/store/cookie.js
index eeb6714..0e048e4 100644
--- a/utils/store/cookie.js
+++ b/utils/store/cookie.js
@@ -37,6 +37,7 @@ function _has(key) {
return
}
let value = uni.getStorageSync(key)
+ console.log(key)
if (value) {
return true
}
diff --git a/剩余问题.js b/剩余问题.js
deleted file mode 100644
index 69e7f7a..0000000
--- a/剩余问题.js
+++ /dev/null
@@ -1,32 +0,0 @@
-// 1、轮播背景问题
-// ~~ 延后处理
-
-// 3、充值签名错误
-// ? 未测试出该问题
-
-// 页面都多了一个头部
-// ~~ 需要打包h5的时候单独修改配置
-
-// 6、评价图片上传不了
-// ?接口报错,反馈给老徐了
-
-// 8、小程序绑定手机号报错
-// ?接口报错,反馈给老徐了
-
-// 12、h5分享关系没形成,看下你那登陆怎么处理的参考下以前的h5
-// ?前端功能修改完,后台交给老徐了
-
-// 13、海报分享,分享分享调整没问题,因为是首页,但是,商品详情海报,拼团海报,砍价海报路由跳转会有问题
-// ?前端功能修改完,后台交给老徐了
-// 海报相关页面
-// components/StorePoster.vue 商品详情
-// > 根据用户来源生成二维码
-// pages/activity/Poster/index 拼团
-// > 根据from
-// pages/activity/Poster/index 砍价
-// > 根据from
-// pages/user/promotion/Poster/index 分销
-
-// 14、小程序已经开启了分享形成关系的问题看下
-// ! 需沟通
-