|
@@ -1,129 +1,126 @@
|
|
|
-import {
|
|
|
|
|
- recordLog
|
|
|
|
|
-} from '../api/api.js'
|
|
|
|
|
-import { apple } from '../config/config'
|
|
|
|
|
-
|
|
|
|
|
-const formatTime = date => {
|
|
|
|
|
- const year = date.getFullYear()
|
|
|
|
|
- const month = date.getMonth() + 1
|
|
|
|
|
- const day = date.getDate()
|
|
|
|
|
- const hour = date.getHours()
|
|
|
|
|
- const minute = date.getMinutes()
|
|
|
|
|
- const second = date.getSeconds()
|
|
|
|
|
-
|
|
|
|
|
- return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
|
|
|
|
|
-}
|
|
|
|
|
|
|
+import { recordLog } from "../api/api.js";
|
|
|
|
|
+import { apple } from "../config/config";
|
|
|
|
|
+
|
|
|
|
|
+const formatTime = (date) => {
|
|
|
|
|
+ const year = date.getFullYear();
|
|
|
|
|
+ const month = date.getMonth() + 1;
|
|
|
|
|
+ const day = date.getDate();
|
|
|
|
|
+ const hour = date.getHours();
|
|
|
|
|
+ const minute = date.getMinutes();
|
|
|
|
|
+ const second = date.getSeconds();
|
|
|
|
|
+
|
|
|
|
|
+ return `${[year, month, day].map(formatNumber).join("/")} ${[hour, minute, second].map(formatNumber).join(":")}`;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-const formatNumber = n => {
|
|
|
|
|
- n = n.toString()
|
|
|
|
|
- return n[1] ? n : `0${n}`
|
|
|
|
|
-}
|
|
|
|
|
|
|
+const formatNumber = (n) => {
|
|
|
|
|
+ n = n.toString();
|
|
|
|
|
+ return n[1] ? n : `0${n}`;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
// 跳转到书籍详情页
|
|
// 跳转到书籍详情页
|
|
|
export const goToBookDetail = (options, query) => {
|
|
export const goToBookDetail = (options, query) => {
|
|
|
- console.log('goToBookDetail option:', options)
|
|
|
|
|
- // 检查必要参数
|
|
|
|
|
- if (!options || (!options.bookId || !options.wxBookId)) {
|
|
|
|
|
- console.warn('书籍ID不能为空');
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ console.log("goToBookDetail option:", options);
|
|
|
|
|
+ // 检查必要参数
|
|
|
|
|
+ if (!options || !options.bookId || !options.wxBookId) {
|
|
|
|
|
+ console.warn("书籍ID不能为空");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let url = "";
|
|
|
|
|
+
|
|
|
|
|
+ // 根据不同参数构建不同的URL
|
|
|
|
|
+ if (options.wxBookId) {
|
|
|
|
|
+ // 微信书籍ID跳转
|
|
|
|
|
+ url = `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?share=1&bookId=${options.wxBookId}&disableAutoShowChargeDialog=1`;
|
|
|
|
|
+
|
|
|
|
|
+ // 如果有章节ID,添加到URL
|
|
|
|
|
+ if (options.chapterId) {
|
|
|
|
|
+ url += `&chapterId=${options.chapterId}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let url = '';
|
|
|
|
|
-
|
|
|
|
|
- // 根据不同参数构建不同的URL
|
|
|
|
|
- if (options.wxBookId) {
|
|
|
|
|
- // 微信书籍ID跳转
|
|
|
|
|
- url = `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?share=1&bookId=${options.wxBookId}&disableAutoShowChargeDialog=1`;
|
|
|
|
|
-
|
|
|
|
|
- // 如果有章节ID,添加到URL
|
|
|
|
|
- if (options.chapterId) {
|
|
|
|
|
- url += `&chapterId=${options.chapterId}`;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (options.bookId) {
|
|
|
|
|
- url += `&innerBookId=${options.bookId}`;
|
|
|
|
|
- }
|
|
|
|
|
- if (query) {
|
|
|
|
|
- url += query
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (options.bookId) {
|
|
|
|
|
+ url += `&innerBookId=${options.bookId}`;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- wx.navigateTo({
|
|
|
|
|
- url,
|
|
|
|
|
- fail: (err) => {
|
|
|
|
|
- console.error('跳转书籍详情页失败:', err);
|
|
|
|
|
- console.log('url', url);
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '跳转失败,请重试',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (query) {
|
|
|
|
|
+ url += query;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wx.navigateTo({
|
|
|
|
|
+ url,
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ console.error("跳转书籍详情页失败:", err);
|
|
|
|
|
+ console.log("url", url);
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "跳转失败,请重试",
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const goToVideoDetail = (options) => {
|
|
export const goToVideoDetail = (options) => {
|
|
|
- console.log('goToVideoDetail option:', options);
|
|
|
|
|
- if (!options || (!options.videoId) || (!options.tagId)) {
|
|
|
|
|
- console.warn('视频ID或标签ID不能为空');
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- let url = '';
|
|
|
|
|
- // 拼接视频详情页的URL
|
|
|
|
|
- url = `/pages/video/detail?id=${options.videoId}&title=&tag_id=${options.tagId}`;
|
|
|
|
|
- wx.navigateTo({
|
|
|
|
|
- url,
|
|
|
|
|
- success: () => {
|
|
|
|
|
- wx.hideLoading();
|
|
|
|
|
- },
|
|
|
|
|
- fail: (err) => {
|
|
|
|
|
- console.error('跳转视频详情页失败:', err);
|
|
|
|
|
- console.log('url', url);
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '跳转失败,请重试',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
|
|
+ console.log("goToVideoDetail option:", options);
|
|
|
|
|
+ if (!options || !options.videoId || !options.tagId) {
|
|
|
|
|
+ console.warn("视频ID或标签ID不能为空");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let url = "";
|
|
|
|
|
+ // 拼接视频详情页的URL
|
|
|
|
|
+ url = `/pages/video/detail?id=${options.videoId}&title=&tag_id=${options.tagId}`;
|
|
|
|
|
+ wx.navigateTo({
|
|
|
|
|
+ url,
|
|
|
|
|
+ success: () => {
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ console.error("跳转视频详情页失败:", err);
|
|
|
|
|
+ console.log("url", url);
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: "跳转失败,请重试",
|
|
|
|
|
+ icon: "none",
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 随机整数方法
|
|
// 随机整数方法
|
|
|
export const rnd = (min = 0, max = 1) => {
|
|
export const rnd = (min = 0, max = 1) => {
|
|
|
- const random = Math.floor(Math.random() * (max - min + 1) + min)
|
|
|
|
|
- return random
|
|
|
|
|
|
|
+ const random = Math.floor(Math.random() * (max - min + 1) + min);
|
|
|
|
|
+ return random;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 随机整数方法
|
|
// 随机整数方法
|
|
|
export const rndone = (self = []) => {
|
|
export const rndone = (self = []) => {
|
|
|
- return self.length > 0 ? self[rnd(0, self.length - 1)] : ''
|
|
|
|
|
|
|
+ return self.length > 0 ? self[rnd(0, self.length - 1)] : "";
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 拷贝
|
|
* 拷贝
|
|
|
*/
|
|
*/
|
|
|
export function deepCopy(data) {
|
|
export function deepCopy(data) {
|
|
|
- let t = typeof data
|
|
|
|
|
- if (data instanceof Array) {
|
|
|
|
|
- t = 'array'
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let t = typeof data;
|
|
|
|
|
+ if (data instanceof Array) {
|
|
|
|
|
+ t = "array";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let o;
|
|
|
|
|
|
|
|
- let o
|
|
|
|
|
-
|
|
|
|
|
- if (t === 'array') {
|
|
|
|
|
- o = []
|
|
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
|
|
- o.push(deepCopy(data[i]))
|
|
|
|
|
- }
|
|
|
|
|
- } else if (t === 'object') {
|
|
|
|
|
- o = {}
|
|
|
|
|
- for (let i in data) {
|
|
|
|
|
- o[i] = deepCopy(data[i])
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- return data
|
|
|
|
|
|
|
+ if (t === "array") {
|
|
|
|
|
+ o = [];
|
|
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
|
|
+ o.push(deepCopy(data[i]));
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (t === "object") {
|
|
|
|
|
+ o = {};
|
|
|
|
|
+ for (let i in data) {
|
|
|
|
|
+ o[i] = deepCopy(data[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return data;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return o
|
|
|
|
|
|
|
+ return o;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -132,60 +129,67 @@ export function deepCopy(data) {
|
|
|
* @param {*} eventParam 事件参数
|
|
* @param {*} eventParam 事件参数
|
|
|
*/
|
|
*/
|
|
|
export const SendEvent = (eventName, eventParam, self) => {
|
|
export const SendEvent = (eventName, eventParam, self) => {
|
|
|
- try {
|
|
|
|
|
- const app = self || getApp()
|
|
|
|
|
- let eParam = { ...eventParam }
|
|
|
|
|
- eParam.from = app.globalData.from || ''
|
|
|
|
|
-
|
|
|
|
|
- const { brand, model, system, platform } = wx.getDeviceInfo()
|
|
|
|
|
-
|
|
|
|
|
- let opt = {
|
|
|
|
|
- app_id: apple.appKey,
|
|
|
|
|
- app_channel: apple.ghid,
|
|
|
|
|
- app_type: 3,
|
|
|
|
|
- event_id: eventName,
|
|
|
|
|
- os_type: 1,
|
|
|
|
|
- event_value: JSON.stringify(eParam),
|
|
|
|
|
- report_time: Date.now(),
|
|
|
|
|
- trace_id: uuid(),
|
|
|
|
|
- user_agent: JSON.stringify({
|
|
|
|
|
- brand,
|
|
|
|
|
- model,
|
|
|
|
|
- system,
|
|
|
|
|
- platform,
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- opt.union_id = app.globalData.unionId || ''
|
|
|
|
|
- opt.open_id = app.globalData.openId || ''
|
|
|
|
|
- opt.user_id = app.globalData.userCode || ''
|
|
|
|
|
- console.log('uploadlog', eventName, opt.event_value, opt.union_id, opt.open_id, opt.user_id)
|
|
|
|
|
- recordLog(opt)
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('record error:', error)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const app = self || getApp();
|
|
|
|
|
+ let eParam = { ...eventParam };
|
|
|
|
|
+ eParam.from = app.globalData.from || "";
|
|
|
|
|
+
|
|
|
|
|
+ const { brand, model, system, platform } = wx.getDeviceInfo();
|
|
|
|
|
+
|
|
|
|
|
+ let opt = {
|
|
|
|
|
+ app_id: apple.appKey,
|
|
|
|
|
+ app_channel: apple.ghid,
|
|
|
|
|
+ app_type: 3,
|
|
|
|
|
+ event_id: eventName,
|
|
|
|
|
+ os_type: 1,
|
|
|
|
|
+ event_value: JSON.stringify(eParam),
|
|
|
|
|
+ report_time: Date.now(),
|
|
|
|
|
+ trace_id: uuid(),
|
|
|
|
|
+ user_agent: JSON.stringify({
|
|
|
|
|
+ brand,
|
|
|
|
|
+ model,
|
|
|
|
|
+ system,
|
|
|
|
|
+ platform,
|
|
|
|
|
+ }),
|
|
|
|
|
+ };
|
|
|
|
|
+ console.log(wx.getStorageSync("openId"));
|
|
|
|
|
+ opt.union_id = wx.getStorageSync("unionId") || "";
|
|
|
|
|
+ opt.open_id = wx.getStorageSync("openId") || "";
|
|
|
|
|
+ opt.user_id = wx.getStorageSync("userCode") || "";
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ "uploadlog",
|
|
|
|
|
+ eventName,
|
|
|
|
|
+ opt.event_value,
|
|
|
|
|
+ opt.union_id,
|
|
|
|
|
+ opt.open_id,
|
|
|
|
|
+ opt.user_id,
|
|
|
|
|
+ );
|
|
|
|
|
+ recordLog(opt);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error("record error:", error);
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
// 生成uuid
|
|
// 生成uuid
|
|
|
export const uuid = function () {
|
|
export const uuid = function () {
|
|
|
- var s = [];
|
|
|
|
|
- var hexDigits = "0123456789abcdef";
|
|
|
|
|
- for (var i = 0; i < 36; i++) {
|
|
|
|
|
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
|
|
|
- }
|
|
|
|
|
- s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
|
|
|
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
|
|
|
- s[8] = s[13] = s[18] = s[23] = "-";
|
|
|
|
|
- var uuid = s.join("");
|
|
|
|
|
- return uuid
|
|
|
|
|
|
|
+ var s = [];
|
|
|
|
|
+ var hexDigits = "0123456789abcdef";
|
|
|
|
|
+ for (var i = 0; i < 36; i++) {
|
|
|
|
|
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
|
|
|
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
|
|
|
+ s[8] = s[13] = s[18] = s[23] = "-";
|
|
|
|
|
+ var uuid = s.join("");
|
|
|
|
|
+ return uuid;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
- formatTime,
|
|
|
|
|
- goToBookDetail,
|
|
|
|
|
- rnd,
|
|
|
|
|
- rndone,
|
|
|
|
|
- deepCopy,
|
|
|
|
|
- SendEvent,
|
|
|
|
|
- goToVideoDetail
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ formatTime,
|
|
|
|
|
+ goToBookDetail,
|
|
|
|
|
+ rnd,
|
|
|
|
|
+ rndone,
|
|
|
|
|
+ deepCopy,
|
|
|
|
|
+ SendEvent,
|
|
|
|
|
+ goToVideoDetail,
|
|
|
|
|
+};
|