/** * @author xiaoping * @email edwardhjp@gmail.com * @create date 2018-07-13 11:17:54 * @modify date 2018-07-13 11:17:54 * @desc [打开] */ import { qsParse, qsStringify, encode } from '../security' // app端内打开新的webview,只支持/xxx的相对形式,如果hash不存在,设置hash='' export function openUrl (url, noQuery = false, hash = '#') { let hrefArr = location.href.split('.htm') let preUrl = '/' if (hrefArr.length > 1) { preUrl = hrefArr[0].replace(/^https?:/, '') + '.htm' } let q = qsParse() let qs = qsStringify(q) if (q._ali_new_window_open_ === undefined) { qs = `_ali_new_window_open_=true&` + qs } const realUrl = `${preUrl}?${qs}${hash}${url}` window.open(realUrl) } export function generateUrl (url, noQuery = false, hash = '#') { let hrefArr = location.href.split('.htm') let preUrl = '/' if (hrefArr.length > 1) { preUrl = hrefArr[0].replace(/^https?:/, '') + '.htm' } let q = qsParse() let qs = qsStringify(q) if (q._ali_new_window_open_ === undefined) { qs = `_ali_new_window_open_=true&` + qs } return `${preUrl}?${qs}${hash}${url}` } // 打开用户管理页面 export async function genUserUrl (version: string, options: any): Promise { let urlKey = '' let { source, page, isPre } = options const isDebug = localStorage['__isDebug'] === 'true' page = page || '' if (!version || !source) { console.error('请添加版本号和品类标识符 https://lark.alipay.com/tmall-iot/framework/page-user') } if (isPre || isDebug) { urlKey = 'pre-page-users' } else { urlKey = 'iot-page-users' } const base = `https://ju.taobao.com/m/jusp/alone/${urlKey}/mtp.htm` const qs = qsStringify(options) const url = `${base}?` + `_ali_new_window_open_=true&` + `_ali_status_bar_=false&` + `_ali_nav_bar_=false&` + `_ali_bounce_=false&` + `version=${version}` + `${isDebug ? '&debug=true' : ''}` + `#/${page}?${qs}` return url } // 打开睡眠曲线页面 export async function genSleepUrl (version: string, options: any): Promise { let urlKey = '' let { source, page, isPre } = options const isDebug = localStorage['__isDebug'] === 'true' page = page || '' if (!version || !source) { console.error('请添加版本号和品类标识符 https://lark.alipay.com/tmall-iot/framework/page-sleep') } if (isPre || isDebug) { urlKey = 'test-page-sleep' } else { urlKey = 'iot-page-sleep' } const base = `https://ju.taobao.com/m/jusp/alone/${urlKey}/mtp.htm` const qs = qsStringify(options) const url = `${base}?` + `_ali_new_window_open_=true&` + `_ali_status_bar_=false&` + `_ali_nav_bar_=false&` + `_ali_bounce_=false&` + `version=${version}` + `${isDebug ? '&debug=true' : ''}` + `#/${page}?${qs}` return url } // 打开能耗管理页面 export async function genEnergyUrl (version: string, options: any): Promise { let urlKey = '' let { source, page, isPre } = options const isDebug = localStorage['__isDebug'] === 'true' page = page || '' if (!version || !source) { console.error('请添加版本号和品类标识符 https://lark.alipay.com/tmall-iot/framework/page-energy') } if (isPre || isDebug) { urlKey = 'pre-page-energy' } else { urlKey = 'iot-page-energy' } const base = `https://ju.taobao.com/m/jusp/alone/${urlKey}/mtp.htm` const qs = qsStringify(options) const url = `${base}?` + `_ali_new_window_open_=true&` + `_ali_status_bar_=false&` + `_ali_nav_bar_=false&` + `_ali_bounce_=false&` + `version=${version}` + `${isDebug ? '&debug=true' : ''}` + `#/${page}?${qs}` return url }