|
|
@@ -50,8 +50,9 @@ Page({
|
|
|
const isHomePath = /^https?:\/\/www\.yuban\.co\/home([/?#]|$)/.test(path);
|
|
|
|
|
|
// 引导页直达 H5 首页时走快速路径:
|
|
|
- // 仅设置 web-view URL,避免额外参数拼接和 Parse 查询造成首开延迟。
|
|
|
+ // 仅补齐缺失的登录/欢迎参数,避免额外 Parse 查询造成首开延迟。
|
|
|
if (isSkipAuth && isHomePath) {
|
|
|
+ path = this.ensureHomeAuthQuery(path);
|
|
|
this.setData({ path });
|
|
|
return;
|
|
|
}
|
|
|
@@ -283,6 +284,67 @@ Page({
|
|
|
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 直达 /home 时补齐 token/userId/mobile/fromStartup,不覆盖 URL 已有值。
|
|
|
+ */
|
|
|
+ ensureHomeAuthQuery: function (path) {
|
|
|
+ try {
|
|
|
+ const hasQuery = path.indexOf('?') !== -1;
|
|
|
+ const existingParams = new Set();
|
|
|
+ if (hasQuery) {
|
|
|
+ const queryString = path.split('?')[1] || '';
|
|
|
+ queryString.split('&').forEach((param) => {
|
|
|
+ const key = param.split('=')[0];
|
|
|
+ if (key) existingParams.add(key);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const append = [];
|
|
|
+ if (!existingParams.has('fromStartup')) {
|
|
|
+ append.push('fromStartup=1');
|
|
|
+ }
|
|
|
+
|
|
|
+ let token = null;
|
|
|
+ let userId = null;
|
|
|
+ let mobile = null;
|
|
|
+ try {
|
|
|
+ const currentUser = Parse && Parse.User ? Parse.User.current() : null;
|
|
|
+ if (currentUser) {
|
|
|
+ token = currentUser.getSessionToken() || null;
|
|
|
+ userId = currentUser.id || null;
|
|
|
+ mobile = currentUser.get('mobile') || null;
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (!token) token = wx.getStorageSync('sessionToken') || null;
|
|
|
+ if (!userId) userId = wx.getStorageSync('userLogin') || null;
|
|
|
+ if (!mobile) {
|
|
|
+ const userInfo = wx.getStorageSync('userInfo') || {};
|
|
|
+ mobile = userInfo.mobile || null;
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+
|
|
|
+ if (token && !existingParams.has('token')) {
|
|
|
+ append.push('token=' + encodeURIComponent(token));
|
|
|
+ }
|
|
|
+ if (userId && !existingParams.has('userId')) {
|
|
|
+ append.push('userId=' + encodeURIComponent(userId));
|
|
|
+ }
|
|
|
+ if (mobile && !existingParams.has('mobile')) {
|
|
|
+ append.push('mobile=' + encodeURIComponent(mobile));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (append.length === 0) return path;
|
|
|
+ return path + (hasQuery ? '&' : '?') + append.join('&');
|
|
|
+ } catch (e) {
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 处理来自 H5 页面的消息
|
|
|
*/
|