From c9afb569b193d3b2635d49db03f723882ec3530c Mon Sep 17 00:00:00 2001 From: lipenggao Date: Wed, 16 Oct 2024 17:56:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.axml | 2 +- pages/index/index.js | 13 +++++++--- pages/search/search.js | 5 ++-- pages/video/video.js | 38 +++++++++++++++++------------- pages/videoAndroid/videoAndroid.js | 20 +++++++++------- utils/utils.js | 13 ++++++++++ 6 files changed, 59 insertions(+), 32 deletions(-) diff --git a/pages/index/index.axml b/pages/index/index.axml index 1b637f9..8af5ff1 100644 --- a/pages/index/index.axml +++ b/pages/index/index.axml @@ -56,7 +56,7 @@ - + diff --git a/pages/index/index.js b/pages/index/index.js index a0e226d..9b9d829 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -1,3 +1,4 @@ +import { objectToQueryString } from '../../utils/utils' Page({ data: { baoxianFlag: false, @@ -18,15 +19,16 @@ Page({ const sid = query.sid || ''; const id = query.id || ''; const tid = query.tid || ''; - const systemInfo = getApp().globalData.systemInfo; + const systemInfo = my.getSystemInfoSync(); + const isUrlString = objectToQueryString(query) if (sid || id || tid) { if (systemInfo.platform == 'android' || systemInfo.platform == 'Android') { my.navigateTo({ - url: `/pages/videoAndroid/videoAndroid?sid=${sid}&id=${id}&tid=${tid}`, + url: `/pages/videoAndroid/videoAndroid?${isUrlString}`, }); } else { my.navigateTo({ - url: `/pages/video/video?sid=${sid}&id=${id}&tid=${tid}` + url: `/pages/video/video?${isUrlString}` }); } } else { @@ -38,6 +40,10 @@ Page({ }, onShow() { // 页面显示 + const systemInfo = my.getSystemInfoSync(); + this.setData({ + systemInfo, + }) this.isGetList(); }, @@ -117,6 +123,7 @@ Page({ toPathVideo(event) { const data = event.target.dataset.item; const systemInfo = this.data.systemInfo; + console.log(systemInfo, "systemInfo") if (systemInfo.platform == 'android' || systemInfo.platform == 'Android') { my.navigateTo({ url: `/pages/videoAndroid/videoAndroid?sid=${data.id}`, diff --git a/pages/search/search.js b/pages/search/search.js index fecbe5e..ef8f88d 100644 --- a/pages/search/search.js +++ b/pages/search/search.js @@ -11,7 +11,7 @@ Page({ onShow() { const historyData = my.getStorageSync({ key: 'historySearch' }); this.setData({ - historySearch: historyData.data + historySearch: historyData.data || [], }) }, @@ -36,12 +36,12 @@ Page({ console.log(res, Array.isArray(res.data), "findfind") if (Array.isArray(res.data)) { historySearch.push(event); - this.setHistorySearch(historySearch); this.setData({ searchList: res.data, searchKeyword: event, searchFlag: true }) + this.setHistorySearch(historySearch); } }) }, @@ -90,6 +90,7 @@ Page({ httpRequest(paramenter).then(res => { console.log(res, Array.isArray(res.data), "findfind") if (Array.isArray(res.data)) { + console.log(historySearch, 'historySearch') historySearch.push(item); this.setHistorySearch(historySearch); this.setData({ diff --git a/pages/video/video.js b/pages/video/video.js index fd6cc91..ec99d41 100644 --- a/pages/video/video.js +++ b/pages/video/video.js @@ -1,4 +1,5 @@ -import { imageBasUrl } from '../../utils/config' +import { imageBasUrl } from '../../utils/config'; +import { objectToQueryString } from '../../utils/utils' const { httpRequest } = getApp(); // import { throttle } from 'lodash'; // import { throttle } from '../../utils/throttle' @@ -28,7 +29,8 @@ Page({ batchAllOrder: 0, batchAllList: [], isThrottle: null, - pageHideFlag: true + pageHideFlag: true, + initParams: {} }, // 获取其它信息 isOtherFn() { @@ -118,24 +120,24 @@ Page({ }, // 获取 剧情 - async isVideoPaymentFn(sid, id, tid) { + async isVideoPaymentFn(params) { - const body = {}; + // const body = {}; - if (sid) { - body.sid = sid; - } - if (sid) { - body.id = id; - } - if (sid) { - body.tid = tid; - } + // if (sid) { + // body.sid = sid; + // } + // if (sid) { + // body.id = id; + // } + // if (sid) { + // body.tid = tid; + // } const paramVideo = { path: '/videoread', method: 'POST', - body: body + body: params } const videoRead = await httpRequest(paramVideo); @@ -198,7 +200,7 @@ Page({ content: res.msg || '购买成功', duration: 1000, }) - this.isVideoPaymentFn(sid); + this.isVideoPaymentFn({ sid: sid, id: videoInfoObj.id, }); } }).catch(err => { if (err.status == 2) { @@ -334,7 +336,8 @@ Page({ this.setData({ sid: sid, id: id, - tid: tid + tid: tid, + initParams: query }) }, @@ -342,8 +345,9 @@ Page({ const sid = this.data.sid; const id = this.data.id; const tid = this.data.tid; + const initParams = this.data.initParams; this.isOtherFn(); - this.isVideoPaymentFn(sid, id, tid); + this.isVideoPaymentFn(initParams); // const lodash = require('lodash'); const isThrottle = _.throttle((current) => { let id = ''; diff --git a/pages/videoAndroid/videoAndroid.js b/pages/videoAndroid/videoAndroid.js index c0a1f86..f39d594 100644 --- a/pages/videoAndroid/videoAndroid.js +++ b/pages/videoAndroid/videoAndroid.js @@ -1,4 +1,5 @@ -import { imageBasUrl } from '../../utils/config' +import { imageBasUrl } from '../../utils/config'; +import { objectToQueryString } from '../../utils/utils' const { httpRequest } = getApp(); // import { throttle } from 'lodash'; // import { throttle } from '../../utils/throttle' @@ -32,7 +33,8 @@ Page({ videoDuration: '0.00', currentTime: '0.00', sliderMax: 100, - sliderValue: 0 + sliderValue: 0, + initParams: {} }, // 获取其它信息 isOtherFn() { @@ -122,13 +124,11 @@ Page({ }, // 获取 剧情 - async isVideoPaymentFn(sid) { + async isVideoPaymentFn(isBody) { const paramVideo = { path: '/videoread', method: 'POST', - body: { - sid: sid - } + body: isBody } const videoRead = await httpRequest(paramVideo); @@ -190,7 +190,7 @@ Page({ content: res.msg || '购买成功', duration: 1000, }) - this.isVideoPaymentFn(sid); + this.isVideoPaymentFn({ sid, id: videoInfoObj.id, }); } }).catch(err => { if (err.status == 2) { @@ -450,14 +450,16 @@ Page({ onLoad(query) { const sid = query.sid; this.setData({ - sid: sid + sid: sid, + initParams: query }) }, onShow() { const sid = this.data.sid; + const initParams = this.data.initParams; this.isOtherFn(); - this.isVideoPaymentFn(sid); + this.isVideoPaymentFn(initParams); // const lodash = require('lodash'); const isThrottle = _.throttle((current) => { let id = ''; diff --git a/utils/utils.js b/utils/utils.js index ee7093f..faa8c79 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -14,4 +14,17 @@ export const storageUid = (uid) => { uid: uid }, }); +} + +export function objectToQueryString(obj) { + return Object.keys(obj).map(key => { + let value = obj[key]; + // 处理数组情况 + if (Array.isArray(value)) { + value = value.map(v => encodeURIComponent(v)).join(','); + } else { + value = encodeURIComponent(value); + } + return `${encodeURIComponent(key)}=${value}`; + }).join('&'); } \ No newline at end of file