Commit d640b8fa by 李伟康

增加媒体资源版本号

1 parent 2d8cbc61
import { IMG_URL } from '~/utils/constantData' import { IMG_URL, IMG_VERSION } from '~/utils/constantData'
module.exports = Behavior({ module.exports = Behavior({
data: { data: {
IMGURL: IMG_URL IMGURL: IMG_URL,
IMG_VERSION: IMG_VERSION()
} }
}) })
const _routeHooks = Symbol('_routeHooks') const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query') const _query = Symbol('_query')
const _routerList = Symbol('_routerList') const _routerList = Symbol('_routerList')
import { IMG_URL } from '~/utils/constantData' import { IMG_URL, IMG_VERSION } from '~/utils/constantData'
import { generateRoutList } from './wxOnAppRoute.js' import { generateRoutList } from './wxOnAppRoute.js'
import { getNavigationBarTitleText } from '~/utils/cache/storageApi' import { getNavigationBarTitleText } from '~/utils/cache/storageApi'
import { getUserInfo } from '~/utils/cache/userInfo' import { getUserInfo } from '~/utils/cache/userInfo'
...@@ -15,8 +15,8 @@ class Router { ...@@ -15,8 +15,8 @@ class Router {
wx.onAppRoute(e => { wx.onAppRoute(e => {
let thisPage = this.getPageInstance() let thisPage = this.getPageInstance()
if (thisPage) { if (thisPage) {
thisPage.setData({ IMG_URL }) thisPage.setData({ IMG_URL, img_version: IMG_VERSION() })
if(Object.keys(this[_query]).length) thisPage.options = { if (Object.keys(this[_query]).length) thisPage.options = {
...thisPage.options, ...thisPage.options,
...this[_query] ...this[_query]
} }
...@@ -58,7 +58,7 @@ class Router { ...@@ -58,7 +58,7 @@ class Router {
return pages[pages.length - size] return pages[pages.length - size]
} }
checkRouter(route, events) { checkRouter (route, events) {
this[_query] = events || {} this[_query] = events || {}
const [_parent, _name, last_name] = route.split('.') const [_parent, _name, last_name] = route.split('.')
let name = route let name = route
...@@ -95,7 +95,7 @@ class Router { ...@@ -95,7 +95,7 @@ class Router {
} }
} }
/**跳转至H5 */ /**跳转至H5 */
jumpH5(url) { jumpH5 (url) {
wx.navigateTo({ wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}` url: `/pages/webView/webView?url=${encodeURIComponent(url)}`
}) })
...@@ -103,7 +103,7 @@ class Router { ...@@ -103,7 +103,7 @@ class Router {
/**页面跳转 /**页面跳转
* *
*/ */
jump(e) { jump (e) {
const item = e.currentTarget.dataset const item = e.currentTarget.dataset
this.go(item.url, item) this.go(item.url, item)
} }
...@@ -111,7 +111,7 @@ class Router { ...@@ -111,7 +111,7 @@ class Router {
* 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 || * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 ||
* 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 $router.back() 可以返回到原页面。小程序中页面栈最多十层 * 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 $router.back() 可以返回到原页面。小程序中页面栈最多十层
*/ */
go(route, events) { go (route, events) {
let { routerMapItem, query } = this.checkRouter(route, events) let { routerMapItem, query } = this.checkRouter(route, events)
if (routerMapItem.isTab) { if (routerMapItem.isTab) {
wx.switchTab({ wx.switchTab({
...@@ -125,14 +125,14 @@ class Router { ...@@ -125,14 +125,14 @@ class Router {
} }
} }
/**关闭所有页面,打开到应用内的某个页面 */ /**关闭所有页面,打开到应用内的某个页面 */
reLaunch(route, events) { reLaunch (route, events) {
let { routerMapItem, query } = this.checkRouter(route, events) let { routerMapItem, query } = this.checkRouter(route, events)
wx.reLaunch({ wx.reLaunch({
url: `${routerMapItem.url}${query}` url: `${routerMapItem.url}${query}`
}) })
} }
/**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */ /**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */
redirectTo(route, events) { redirectTo (route, events) {
let { routerMapItem, query } = this.checkRouter(route, events) let { routerMapItem, query } = this.checkRouter(route, events)
wx.redirectTo({ wx.redirectTo({
url: `${routerMapItem.url}${query}` url: `${routerMapItem.url}${query}`
...@@ -141,7 +141,7 @@ class Router { ...@@ -141,7 +141,7 @@ class Router {
/**prevPageSize = 1 /**prevPageSize = 1
* 返回上prevPageSize页 * 返回上prevPageSize页
* callBack返回上prevPageSize页对象 */ * callBack返回上prevPageSize页对象 */
back(callBack, prevPageSize = 1) { back (callBack, prevPageSize = 1) {
let prevPage = this.getPageInstance(Number(prevPageSize) + 1) let prevPage = this.getPageInstance(Number(prevPageSize) + 1)
if (callBack && 'function' === typeof callBack) callBack(prevPage) if (callBack && 'function' === typeof callBack) callBack(prevPage)
wx.navigateBack({ wx.navigateBack({
...@@ -150,18 +150,18 @@ class Router { ...@@ -150,18 +150,18 @@ class Router {
this.goHome() this.goHome()
}) })
} }
goHome() { goHome () {
let [index] = this[_routerList] let [index] = this[_routerList]
wx.reLaunch({ wx.reLaunch({
url: index.url url: index.url
}) })
} }
/**获取上一个页面传的数据 */ /**获取上一个页面传的数据 */
getData(callBack) { getData (callBack) {
const data = this.getPageInstance().getOpenerEventChannel() const data = this.getPageInstance().getOpenerEventChannel()
if (Object.keys(data).length !== 0) data.on('getData', res => callBack(res)) if (Object.keys(data).length !== 0) data.on('getData', res => callBack(res))
} }
onRoute(fn) { onRoute (fn) {
this[_routeHooks].push(fn) this[_routeHooks].push(fn)
return () => { return () => {
const i = list.indexOf(fn) const i = list.indexOf(fn)
......
...@@ -16,3 +16,8 @@ export const STORAGE_OBJECTkEY = { ...@@ -16,3 +16,8 @@ export const STORAGE_OBJECTkEY = {
firstLogin:'firstLogin', firstLogin:'firstLogin',
authphone:'authphone' authphone:'authphone'
} }
export const IMG_VERSION = () =>{
const accountInfo = wx.getAccountInfoSync()
return accountInfo.miniProgram.version || '1.0.0'
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!