提交 c38db7fa 编写于 作者: Q qiang

build: app

上级 0b29030a
...@@ -7,7 +7,7 @@ function b64DecodeUnicode (str) { ...@@ -7,7 +7,7 @@ function b64DecodeUnicode (str) {
} }
function getCurrentUserInfo () { function getCurrentUserInfo () {
const token = (uni ).getStorageSync('uni_id_token') || ''; const token = ( uni ).getStorageSync('uni_id_token') || '';
const tokenArr = token.split('.'); const tokenArr = token.split('.');
if (!token || tokenArr.length !== 3) { if (!token || tokenArr.length !== 3) {
return { return {
...@@ -461,7 +461,7 @@ function processReturnValue (methodName, res, returnValue, keepReturnValue = fal ...@@ -461,7 +461,7 @@ function processReturnValue (methodName, res, returnValue, keepReturnValue = fal
return processArgs(methodName, res, returnValue, {}, keepReturnValue) return processArgs(methodName, res, returnValue, {}, keepReturnValue)
} }
function wrapper$2 (methodName, method) { function wrapper (methodName, method) {
if (hasOwn(protocols, methodName)) { if (hasOwn(protocols, methodName)) {
const protocol = protocols[methodName]; const protocol = protocols[methodName];
if (!protocol) { // 暂不支持的 api if (!protocol) { // 暂不支持的 api
...@@ -949,7 +949,7 @@ function initProperties (props, isBehavior = false, file = '') { ...@@ -949,7 +949,7 @@ function initProperties (props, isBehavior = false, file = '') {
return properties return properties
} }
function wrapper (event) { function wrapper$2 (event) {
// TODO 又得兼容 mpvue 的 mp 对象 // TODO 又得兼容 mpvue 的 mp 对象
try { try {
event.mp = JSON.parse(JSON.stringify(event)); event.mp = JSON.parse(JSON.stringify(event));
...@@ -1142,7 +1142,7 @@ function getContextVm (vm) { ...@@ -1142,7 +1142,7 @@ function getContextVm (vm) {
} }
function handleEvent (event) { function handleEvent (event) {
event = wrapper(event); event = wrapper$2(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]] // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset; const dataset = (event.currentTarget || event.target).dataset;
...@@ -1308,7 +1308,7 @@ function getEventChannel (id) { ...@@ -1308,7 +1308,7 @@ function getEventChannel (id) {
return eventChannelStack.shift() return eventChannelStack.shift()
} }
const hooks$3 = [ const hooks = [
'onShow', 'onShow',
'onHide', 'onHide',
'onError', 'onError',
...@@ -1409,7 +1409,7 @@ function parseBaseApp (vm, { ...@@ -1409,7 +1409,7 @@ function parseBaseApp (vm, {
}); });
} }
initHooks(appOptions, hooks$3); initHooks(appOptions, hooks);
return appOptions return appOptions
} }
...@@ -1494,27 +1494,27 @@ function handleLink (event) { ...@@ -1494,27 +1494,27 @@ function handleLink (event) {
vueOptions.parent = parentVm; vueOptions.parent = parentVm;
} }
function parseApp$1 (vm) { function parseApp (vm) {
return parseBaseApp(vm, { return parseBaseApp(vm, {
mocks, mocks,
initRefs initRefs
}) })
} }
const hooks$2 = [ const hooks$1 = [
'onUniNViewMessage' 'onUniNViewMessage'
]; ];
function parseApp (vm) { function parseApp$1 (vm) {
const appOptions = parseApp$1(vm); const appOptions = parseApp(vm);
initHooks(appOptions, hooks$2); initHooks(appOptions, hooks$1);
return appOptions return appOptions
} }
function createApp (vm) { function createApp (vm) {
App(parseApp(vm)); App(parseApp$1(vm));
return vm return vm
} }
...@@ -1653,15 +1653,15 @@ function parseBaseComponent (vueComponentOptions, { ...@@ -1653,15 +1653,15 @@ function parseBaseComponent (vueComponentOptions, {
return [componentOptions, VueComponent] return [componentOptions, VueComponent]
} }
function parseComponent$1 (vueComponentOptions) { function parseComponent (vueComponentOptions) {
return parseBaseComponent(vueComponentOptions, { return parseBaseComponent(vueComponentOptions, {
isPage, isPage,
initRelation initRelation
}) })
} }
function parseComponent (vueComponentOptions) { function parseComponent$1 (vueComponentOptions) {
const componentOptions = parseComponent$1(vueComponentOptions); const componentOptions = parseComponent(vueComponentOptions);
componentOptions.methods.$getAppWebview = function () { componentOptions.methods.$getAppWebview = function () {
return plus.webview.getWebviewById(`${this.__wxWebviewId__}`) return plus.webview.getWebviewById(`${this.__wxWebviewId__}`)
...@@ -1669,21 +1669,21 @@ function parseComponent (vueComponentOptions) { ...@@ -1669,21 +1669,21 @@ function parseComponent (vueComponentOptions) {
return componentOptions return componentOptions
} }
const hooks$1 = [ const hooks$2 = [
'onShow', 'onShow',
'onHide', 'onHide',
'onUnload' 'onUnload'
]; ];
hooks$1.push(...PAGE_EVENT_HOOKS); hooks$2.push(...PAGE_EVENT_HOOKS);
function parseBasePage (vuePageOptions, { function parseBasePage (vuePageOptions, {
isPage, isPage,
initRelation initRelation
}) { }) {
const pageOptions = parseComponent(vuePageOptions); const pageOptions = parseComponent$1(vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vuePageOptions); initHooks(pageOptions.methods, hooks$2, vuePageOptions);
pageOptions.methods.onLoad = function (query) { pageOptions.methods.onLoad = function (query) {
this.options = query; this.options = query;
...@@ -1699,14 +1699,14 @@ function parseBasePage (vuePageOptions, { ...@@ -1699,14 +1699,14 @@ function parseBasePage (vuePageOptions, {
return pageOptions return pageOptions
} }
function parsePage$1 (vuePageOptions) { function parsePage (vuePageOptions) {
return parseBasePage(vuePageOptions, { return parseBasePage(vuePageOptions, {
isPage, isPage,
initRelation initRelation
}) })
} }
const hooks = [ const hooks$3 = [
'onBackPress', 'onBackPress',
'onNavigationBarButtonTap', 'onNavigationBarButtonTap',
'onNavigationBarSearchInputChanged', 'onNavigationBarSearchInputChanged',
...@@ -1715,28 +1715,28 @@ const hooks = [ ...@@ -1715,28 +1715,28 @@ const hooks = [
'onNavigationBarSearchInputFocusChanged' 'onNavigationBarSearchInputFocusChanged'
]; ];
function parsePage (vuePageOptions) { function parsePage$1 (vuePageOptions) {
const pageOptions = parsePage$1(vuePageOptions); const pageOptions = parsePage(vuePageOptions);
initHooks(pageOptions.methods, hooks); initHooks(pageOptions.methods, hooks$3);
return pageOptions return pageOptions
} }
function createPage (vuePageOptions) { function createPage (vuePageOptions) {
{ {
return Component(parsePage(vuePageOptions)) return Component(parsePage$1(vuePageOptions))
} }
} }
function createComponent (vueOptions) { function createComponent (vueOptions) {
{ {
return Component(parseComponent(vueOptions)) return Component(parseComponent$1(vueOptions))
} }
} }
function createSubpackageApp (vm) { function createSubpackageApp (vm) {
const appOptions = parseApp(vm); const appOptions = parseApp$1(vm);
const app = getApp({ const app = getApp({
allowDefault: true allowDefault: true
}); });
...@@ -1771,7 +1771,7 @@ function createSubpackageApp (vm) { ...@@ -1771,7 +1771,7 @@ function createSubpackageApp (vm) {
} }
function createPlugin (vm) { function createPlugin (vm) {
const appOptions = parseApp(vm); const appOptions = parseApp$1(vm);
if (isFn(appOptions.onShow) && wx.onAppShow) { if (isFn(appOptions.onShow) && wx.onAppShow) {
wx.onAppShow((...args) => { wx.onAppShow((...args) => {
appOptions.onShow.apply(vm, args); appOptions.onShow.apply(vm, args);
...@@ -1821,7 +1821,7 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') { ...@@ -1821,7 +1821,7 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) { if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
return return
} }
return promisify(name, wrapper$2(name, wx[name])) return promisify(name, wrapper(name, wx[name]))
}, },
set (target, name, value) { set (target, name, value) {
target[name] = value; target[name] = value;
...@@ -1843,7 +1843,7 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') { ...@@ -1843,7 +1843,7 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
Object.keys(wx).forEach(name => { Object.keys(wx).forEach(name => {
if (hasOwn(wx, name) || hasOwn(protocols, name)) { if (hasOwn(wx, name) || hasOwn(protocols, name)) {
uni$1[name] = promisify(name, wrapper$2(name, wx[name])); uni$1[name] = promisify(name, wrapper(name, wx[name]));
} }
}); });
} }
......
...@@ -225,6 +225,7 @@ var serviceContext = (function () { ...@@ -225,6 +225,7 @@ var serviceContext = (function () {
'login', 'login',
'checkSession', 'checkSession',
'getUserInfo', 'getUserInfo',
'getUserProfile',
'preLogin', 'preLogin',
'closeAuthView', 'closeAuthView',
'share', 'share',
...@@ -252,7 +253,8 @@ var serviceContext = (function () { ...@@ -252,7 +253,8 @@ var serviceContext = (function () {
const ad = [ const ad = [
'createRewardedVideoAd', 'createRewardedVideoAd',
'createFullScreenVideoAd', 'createFullScreenVideoAd',
'createInterstitialAd' 'createInterstitialAd',
'createInteractiveAd'
]; ];
const apis = [ const apis = [
...@@ -286,6 +288,56 @@ var serviceContext = (function () { ...@@ -286,6 +288,56 @@ var serviceContext = (function () {
window.addEventListener('test-passive', null, opts); window.addEventListener('test-passive', null, opts);
} catch (e) {} } catch (e) {}
function b64DecodeUnicode (str) {
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
}
function getCurrentUserInfo () {
const token = ( uni ).getStorageSync('uni_id_token') || '';
const tokenArr = token.split('.');
if (!token || tokenArr.length !== 3) {
return {
uid: null,
role: [],
permission: [],
tokenExpired: 0
}
}
let userInfo;
try {
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
} catch (error) {
throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message)
}
userInfo.tokenExpired = userInfo.exp * 1000;
delete userInfo.exp;
delete userInfo.iat;
return userInfo
}
function uniIdMixin (Vue) {
Vue.prototype.uniIDHasRole = function (roleId) {
const {
role
} = getCurrentUserInfo();
return role.indexOf(roleId) > -1
};
Vue.prototype.uniIDHasPermission = function (permissionId) {
const {
permission
} = getCurrentUserInfo();
return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1
};
Vue.prototype.uniIDTokenValid = function () {
const {
tokenExpired
} = getCurrentUserInfo();
return tokenExpired > Date.now()
};
}
const _toString = Object.prototype.toString; const _toString = Object.prototype.toString;
const hasOwnProperty = Object.prototype.hasOwnProperty; const hasOwnProperty = Object.prototype.hasOwnProperty;
...@@ -6873,11 +6925,14 @@ var serviceContext = (function () { ...@@ -6873,11 +6925,14 @@ var serviceContext = (function () {
return options return options
}, data => { }, data => {
return { return {
orientation: data.orientation,
type: data.type,
duration: data.duration, duration: data.duration,
fps: data.fps || 30, size: data.size,
height: data.height, height: data.height,
width: data.width, width: data.width,
size: data.size fps: data.fps || 30,
bitrate: data.bitrate,
} }
}); });
...@@ -7172,6 +7227,7 @@ var serviceContext = (function () { ...@@ -7172,6 +7227,7 @@ var serviceContext = (function () {
responseType, responseType,
sslVerify = true, sslVerify = true,
firstIpv4 = false, firstIpv4 = false,
tls,
timeout = (__uniConfig.networkTimeout && __uniConfig.networkTimeout.request) || 60 * 1000 timeout = (__uniConfig.networkTimeout && __uniConfig.networkTimeout.request) || 60 * 1000
} = {}) { } = {}) {
const stream = requireNativePlugin('stream'); const stream = requireNativePlugin('stream');
...@@ -7225,7 +7281,8 @@ var serviceContext = (function () { ...@@ -7225,7 +7281,8 @@ var serviceContext = (function () {
timeout: timeout || 6e5, timeout: timeout || 6e5,
// 配置和weex模块内相反 // 配置和weex模块内相反
sslVerify: !sslVerify, sslVerify: !sslVerify,
firstIpv4: firstIpv4 firstIpv4: firstIpv4,
tls
}; };
if (method !== 'GET') { if (method !== 'GET') {
options.body = typeof data === 'string' ? data : JSON.stringify(data); options.body = typeof data === 'string' ? data : JSON.stringify(data);
...@@ -7698,6 +7755,12 @@ var serviceContext = (function () { ...@@ -7698,6 +7755,12 @@ var serviceContext = (function () {
}); });
}); });
} }
/**
* 获取用户信息-兼容
*/
function getUserProfile (params, callbackId) {
return getUserInfo(params, callbackId)
}
/** /**
* 获取用户信息 * 获取用户信息
...@@ -10913,7 +10976,7 @@ var serviceContext = (function () { ...@@ -10913,7 +10976,7 @@ var serviceContext = (function () {
constructor (options = {}) { constructor (options = {}) {
super(plus.ad.createInterstitialAd(options), options); super(plus.ad.createInterstitialAd(options), options);
this.load(); this._loadAd();
} }
} }
...@@ -10921,6 +10984,235 @@ var serviceContext = (function () { ...@@ -10921,6 +10984,235 @@ var serviceContext = (function () {
return new InterstitialAd(options) return new InterstitialAd(options)
} }
const sdkCache = {};
const sdkQueue = {};
function initSDK (options) {
const provider = options.provider;
if (typeof sdkCache[provider] === 'object') {
options.success(sdkCache[provider]);
return
}
if (!sdkQueue[provider]) {
sdkQueue[provider] = [];
}
sdkQueue[provider].push(options);
if (sdkCache[provider] === true) {
return
}
sdkCache[provider] = true;
const plugin = requireNativePlugin(provider);
if (!plugin || !plugin.initSDK) {
sdkQueue[provider].forEach((item) => {
item.fail({
code: -1,
message: 'provider [' + provider + '] invalid'
});
});
sdkQueue[provider].length = 0;
sdkCache[provider] = false;
return
}
options.__plugin = plugin;
plugin.initSDK((res) => {
const isSuccess = (res.code === 1 || res.code === '1');
if (isSuccess) {
sdkCache[provider] = plugin;
} else {
sdkCache[provider] = false;
}
sdkQueue[provider].forEach((item) => {
if (isSuccess) {
item.success(item.__plugin);
} else {
item.fail(res);
}
});
sdkQueue[provider].length = 0;
});
}
class InteractiveAd {
constructor (options) {
const _callbacks = this._callbacks = {};
eventNames$1.forEach(item => {
_callbacks[item] = [];
const name = item[0].toUpperCase() + item.substr(1);
this[`on${name}`] = function (callback) {
_callbacks[item].push(callback);
};
});
this._ad = null;
this._adError = '';
this._adpid = options.adpid;
this._provider = options.provider;
this._isLoaded = false;
this._isLoading = false;
this._loadPromiseResolve = null;
this._loadPromiseReject = null;
this._showPromiseResolve = null;
this._showPromiseReject = null;
setTimeout(() => {
this._init();
});
}
_init () {
this._adError = '';
initSDK({
provider: this._provider,
success: (res) => {
this._ad = res;
this._loadAd();
},
fail: (err) => {
this._adError = err;
this._dispatchEvent(eventTypes.error, err);
}
});
}
getProvider () {
return this._provider
}
load () {
return new Promise((resolve, reject) => {
this._loadPromiseResolve = resolve;
this._loadPromiseReject = reject;
if (this._isLoading) {
return
}
if (this._adError) {
this._init();
return
}
if (this._isLoaded) {
resolve();
} else {
this._loadAd();
}
})
}
show () {
return new Promise((resolve, reject) => {
this._showPromiseResolve = resolve;
this._showPromiseReject = reject;
if (this._isLoading) {
return
}
if (this._adError) {
this._init();
return
}
if (this._isLoaded) {
this._showAd();
resolve();
} else {
this._loadAd();
}
})
}
destroy () {
if (this._ad !== null && this._ad.destroy) {
this._ad.destroy({
adpid: this._adpid
});
}
}
_loadAd () {
if (this._ad !== null) {
if (this._isLoading === true) {
return
}
this._isLoading = true;
this._ad.loadData({
adpid: this._adpid
}, (res) => {
this._isLoaded = true;
this._isLoading = false;
this._dispatchEvent(eventTypes.load, res);
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve();
this._loadPromiseResolve = null;
}
if (this._showPromiseResolve != null) {
this._showPromiseResolve();
this._showPromiseResolve = null;
this._showAd();
}
}, (err) => {
this._isLoading = false;
this._dispatchEvent(eventTypes.error, err);
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err));
this._showPromiseReject = null;
}
});
}
}
_showAd () {
if (this._ad !== null && this._isLoaded === true) {
this._ad.show({
adpid: this._adpid
}, (res) => {
this._isLoaded = false;
}, (err) => {
this._isLoaded = false;
this._dispatchEvent(eventTypes.error, err);
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err));
this._showPromiseReject = null;
}
});
}
}
_createError (err) {
const error = new Error(JSON.stringify(err));
error.code = err.code;
error.errMsg = err.message;
return error
}
_dispatchEvent (name, data) {
this._callbacks[name].forEach(callback => {
if (typeof callback === 'function') {
callback(data || {});
}
});
}
}
function createInteractiveAd (options) {
if (!options.provider) {
return new Error('provider invalid')
}
if (!options.adpid) {
return new Error('adpid invalid')
}
return new InteractiveAd(options)
}
var api = /*#__PURE__*/Object.freeze({ var api = /*#__PURE__*/Object.freeze({
__proto__: null, __proto__: null,
startPullDownRefresh: startPullDownRefresh, startPullDownRefresh: startPullDownRefresh,
...@@ -11027,6 +11319,7 @@ var serviceContext = (function () { ...@@ -11027,6 +11319,7 @@ var serviceContext = (function () {
getProvider: getProvider$1, getProvider: getProvider$1,
login: login, login: login,
getUserInfo: getUserInfo, getUserInfo: getUserInfo,
getUserProfile: getUserProfile,
operateWXData: operateWXData, operateWXData: operateWXData,
preLogin: preLogin$1, preLogin: preLogin$1,
closeAuthView: closeAuthView, closeAuthView: closeAuthView,
...@@ -11083,7 +11376,8 @@ var serviceContext = (function () { ...@@ -11083,7 +11376,8 @@ var serviceContext = (function () {
requestComponentInfo: requestComponentInfo$2, requestComponentInfo: requestComponentInfo$2,
createRewardedVideoAd: createRewardedVideoAd, createRewardedVideoAd: createRewardedVideoAd,
createFullScreenVideoAd: createFullScreenVideoAd, createFullScreenVideoAd: createFullScreenVideoAd,
createInterstitialAd: createInterstitialAd createInterstitialAd: createInterstitialAd,
createInteractiveAd: createInteractiveAd
}); });
var platformApi = Object.assign(Object.create(null), api, eventApis); var platformApi = Object.assign(Object.create(null), api, eventApis);
...@@ -22103,6 +22397,8 @@ var serviceContext = (function () { ...@@ -22103,6 +22397,8 @@ var serviceContext = (function () {
initPolyfill(Vue); initPolyfill(Vue);
uniIdMixin(Vue);
Vue.prototype.getOpenerEventChannel = function () { Vue.prototype.getOpenerEventChannel = function () {
if (!this.$root.$scope.eventChannel) { if (!this.$root.$scope.eventChannel) {
this.$root.$scope.eventChannel = new EventChannel(); this.$root.$scope.eventChannel = new EventChannel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册