提交 bb075ada 编写于 作者: Q qiang

Merge tag 'v2.0.0-31920210609001'

v2.0.0-31920210609001

# Conflicts:
#	packages/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js
...@@ -13,6 +13,8 @@ const { ...@@ -13,6 +13,8 @@ const {
generateApiManifest generateApiManifest
} = require('./manifest') } = require('./manifest')
const fixInnerHTML = require('./fixInnerHTML')
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), { const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), {
inlineOptions: require('./vue.config.js') inlineOptions: require('./vue.config.js')
}) })
...@@ -53,6 +55,9 @@ service.run('build', { ...@@ -53,6 +55,9 @@ service.run('build', {
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_PROTOCOL)) JSON.parse(JSON.stringify(process.UNI_SERVICE_API_PROTOCOL))
) )
} }
if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_VIEW === 'true' && process.env.UNI_WATCH !== 'true') {
fixInnerHTML()
}
}).catch(err => { }).catch(err => {
error(err) error(err)
process.exit(1) process.exit(1)
...@@ -85,4 +90,4 @@ if (process.env.UNI_PLATFORM === 'h5' && process.env.UNI_WATCH === 'false') { ...@@ -85,4 +90,4 @@ if (process.env.UNI_PLATFORM === 'h5' && process.env.UNI_WATCH === 'false') {
.catch(err => { .catch(err => {
throw err throw err
}) })
} }
const path = require('path')
const fs = require('fs')
module.exports = function () {
const files = [
path.join(__dirname, '../packages/uni-app-plus/dist/view.umd.min.js'),
path.join(__dirname, '../packages/uni-app-plus/template/v3/__uniappquill.js'),
path.join(__dirname, '../packages/uni-app-plus/template/v3/__uniappquillimageresize.js')
]
files.forEach(filePath => {
const fileContent = fs.readFileSync(filePath, {
encoding: 'utf8'
})
fs.writeFileSync(filePath, fileContent.replace(/\.innerHTML\b/g, '["inner"+"HTML"]'), {
encoding: 'utf8'
})
})
}
...@@ -256,14 +256,14 @@ export default { ...@@ -256,14 +256,14 @@ export default {
|参数名 |类型 |说明 |平台差异说明| |参数名 |类型 |说明 |平台差异说明|
|:- |:- |:- || |:- |:- |:- ||
|orientation|string |画面方向 |微信小程序| |orientation|string |画面方向 |微信小程序、App(3.1.14+)|
|type |string |视频格式 |微信小程序| |type |string |视频格式 |微信小程序、App(3.1.14+)|
|duration |number |视频长度 |微信小程序、App、H5| |duration |number |视频长度 |微信小程序、App(3.1.10+)、H5|
|size |number |视频大小,单位 kB |微信小程序、App、H5| |size |number |视频大小,单位 kB |微信小程序、App(3.1.10+)、H5|
|height |number |视频的长,单位 px |微信小程序、App、H5| |height |number |视频的长,单位 px |微信小程序、App(3.1.10+)、H5|
|width |number |视频的宽,单位 px |微信小程序、App、H5| |width |number |视频的宽,单位 px |微信小程序、App(3.1.10+)、H5|
|fps |number |视频帧率 |微信小程序、App| |fps |number |视频帧率 |微信小程序、App(3.1.14+)|
|bitrate |number |视频码率,单位 kbps|微信小程序| |bitrate |number |视频码率,单位 kbps|微信小程序、App(3.1.14+)|
**res.orientation参数说明** **res.orientation参数说明**
......
...@@ -12,6 +12,9 @@ H5平台登录注意事项: ...@@ -12,6 +12,9 @@ H5平台登录注意事项:
- 普通浏览器上实现微信登录,并非开放API,需要向微信申请,仅个别开发者有此权限 - 普通浏览器上实现微信登录,并非开放API,需要向微信申请,仅个别开发者有此权限
- H5平台的其他登录,比如QQ登录、微博登录,uni-app未封装,请在条件编译里按普通H5写法编写。 - H5平台的其他登录,比如QQ登录、微博登录,uni-app未封装,请在条件编译里按普通H5写法编写。
百度小程序登录注意事项:
- 百度小程序平台需要在button组件的@login事件后再调用 uni.login ,[详见](https://smartprogram.baidu.com/docs/develop/function/login/),否则会返回“请登录”的错误信息,建议在@login事件中调用。
**OBJECT 参数说明** **OBJECT 参数说明**
|参数名|类型|必填|说明|平台差异说明| |参数名|类型|必填|说明|平台差异说明|
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
|backgroundColor|Color |#EBEBEB |未选择的进度条的颜色 | | |backgroundColor|Color |#EBEBEB |未选择的进度条的颜色 | |
|active |Boolean |false |进度条从左往右的动画 | | |active |Boolean |false |进度条从左往右的动画 | |
|active-mode |String |backwards |backwards: 动画从头播;forwards:动画从上次结束点接着播|App、H5、微信小程序、QQ小程序 | |active-mode |String |backwards |backwards: 动画从头播;forwards:动画从上次结束点接着播|App、H5、微信小程序、QQ小程序 |
|duration|number|30|进度增加1%所需毫秒数|App-nvue2.6.1+、微信基础库2.8.2+| |duration|number|30|进度增加1%所需毫秒数|App-nvue2.6.1+、微信基础库2.8.2+、H5 3.1.11+|
|@activeend |EventHandle| |动画完成事件 |微信小程序 | |@activeend |EventHandle| |动画完成事件 |微信小程序 |
**示例** [查看演示](https://hellouniapp.dcloud.net.cn/pages/component/progress/progress) **示例** [查看演示](https://hellouniapp.dcloud.net.cn/pages/component/progress/progress)
......
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
"message": "chore(release): publish %s" "message": "chore(release): publish %s"
} }
}, },
"version": "2.0.0-31920210422002" "version": "2.0.0-31920210609001"
} }
...@@ -214,6 +214,7 @@ const third = [ ...@@ -214,6 +214,7 @@ const third = [
'login', 'login',
'checkSession', 'checkSession',
'getUserInfo', 'getUserInfo',
'getUserProfile',
'preLogin', 'preLogin',
'closeAuthView', 'closeAuthView',
'share', 'share',
...@@ -240,8 +241,9 @@ const third = [ ...@@ -240,8 +241,9 @@ const third = [
const ad = [ const ad = [
'createRewardedVideoAd', 'createRewardedVideoAd',
'createFullScreenVideoAd', 'createFullScreenVideoAd',
'createInterstitialAd' 'createInterstitialAd',
'createInteractiveAd'
] ]
const apis = [ const apis = [
......
...@@ -206,6 +206,7 @@ ...@@ -206,6 +206,7 @@
"uni.login": true, "uni.login": true,
"uni.checkSession": true, "uni.checkSession": true,
"uni.getUserInfo": true, "uni.getUserInfo": true,
"uni.getUserProfile": true,
"uni.share": true, "uni.share": true,
"uni.showShareMenu": true, "uni.showShareMenu": true,
"uni.hideShareMenu": true, "uni.hideShareMenu": true,
...@@ -223,7 +224,8 @@ ...@@ -223,7 +224,8 @@
"title": "广告", "title": "广告",
"apiList": { "apiList": {
"uni.createRewardedVideoAd": true, "uni.createRewardedVideoAd": true,
"uni.createFullScreenVideoAd": true, "uni.createFullScreenVideoAd": true,
"uni.'createInterstitialAd'": true "uni.'createInterstitialAd'": true,
"uni.'createInteractiveAd'": true
} }
}] }]
{ {
"name": "@dcloudio/uni-app-plus-nvue", "name": "@dcloudio/uni-app-plus-nvue",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app app-plus-nvue", "description": "uni-app app-plus-nvue",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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;
...@@ -1292,6 +1342,7 @@ function parseBaseApp (vm, { ...@@ -1292,6 +1342,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "app-plus"; Vue.prototype.mpHost = "app-plus";
...@@ -1750,10 +1801,10 @@ canIUses.forEach(canIUseApi => { ...@@ -1750,10 +1801,10 @@ canIUses.forEach(canIUseApi => {
} }
}); });
let uni = {}; let uni$1 = {};
if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') { if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
uni = new Proxy({}, { uni$1 = new Proxy({}, {
get (target, name) { get (target, name) {
if (hasOwn(target, name)) { if (hasOwn(target, name)) {
return target[name] return target[name]
...@@ -1779,27 +1830,27 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') { ...@@ -1779,27 +1830,27 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
}); });
} else { } else {
Object.keys(baseApi).forEach(name => { Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name]; uni$1[name] = baseApi[name];
}); });
Object.keys(eventApi).forEach(name => { Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name]; uni$1[name] = eventApi[name];
}); });
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni$1[name] = promisify(name, api[name]);
}); });
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[name] = promisify(name, wrapper(name, wx[name])); uni$1[name] = promisify(name, wrapper(name, wx[name]));
} }
}); });
} }
{ {
if (typeof global !== 'undefined') { if (typeof global !== 'undefined') {
global.uni = uni; global.uni = uni$1;
global.UniEmitter = eventApi; global.UniEmitter = eventApi;
} }
} }
...@@ -1810,7 +1861,7 @@ wx.createComponent = createComponent; ...@@ -1810,7 +1861,7 @@ wx.createComponent = createComponent;
wx.createSubpackageApp = createSubpackageApp; wx.createSubpackageApp = createSubpackageApp;
wx.createPlugin = createPlugin; wx.createPlugin = createPlugin;
var uni$1 = uni; var uni$2 = uni$1;
export default uni$1; export default uni$2;
export { createApp, createComponent, createPage, createPlugin, createSubpackageApp }; export { createApp, createComponent, createPage, createPlugin, createSubpackageApp };
...@@ -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',
...@@ -251,8 +252,9 @@ var serviceContext = (function () { ...@@ -251,8 +252,9 @@ 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;
...@@ -1630,10 +1682,13 @@ var serviceContext = (function () { ...@@ -1630,10 +1682,13 @@ var serviceContext = (function () {
function getRealPath (filePath) { function getRealPath (filePath) {
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath; return 'https:' + filePath
} else { }
return addBase(filePath.substr(1)) // 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
} }
return addBase(filePath.substr(1))
} }
// 网络资源或base64 // 网络资源或base64
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) { if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
...@@ -3851,7 +3906,7 @@ var serviceContext = (function () { ...@@ -3851,7 +3906,7 @@ var serviceContext = (function () {
// 无协议的情况补全 https // 无协议的情况补全 https
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath; return 'https:' + filePath
} }
// 网络资源或base64 // 网络资源或base64
...@@ -3866,6 +3921,10 @@ var serviceContext = (function () { ...@@ -3866,6 +3921,10 @@ var serviceContext = (function () {
const wwwPath = 'file://' + _handleLocalPath('_www'); const wwwPath = 'file://' + _handleLocalPath('_www');
// 绝对路径转换为本地文件系统路径 // 绝对路径转换为本地文件系统路径
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
// 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
}
return wwwPath + filePath return wwwPath + filePath
} }
// 相对资源 // 相对资源
...@@ -6756,7 +6815,7 @@ var serviceContext = (function () { ...@@ -6756,7 +6815,7 @@ var serviceContext = (function () {
}, () => { }, () => {
resolve(tempFilePath); resolve(tempFilePath);
}); });
}) : Promise.resolve(); }) : Promise.resolve(tempFilePath);
if (compressed) { if (compressed) {
plus.nativeUI.showWaiting(); plus.nativeUI.showWaiting();
} }
...@@ -6777,7 +6836,7 @@ var serviceContext = (function () { ...@@ -6777,7 +6836,7 @@ var serviceContext = (function () {
result.height = videoInfo.height; result.height = videoInfo.height;
invoke$1(callbackId, result); invoke$1(callbackId, result);
}, },
errorCallback fail: errorCallback
}); });
}); });
} }
...@@ -6866,11 +6925,14 @@ var serviceContext = (function () { ...@@ -6866,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
} }
}); });
...@@ -7165,6 +7227,7 @@ var serviceContext = (function () { ...@@ -7165,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');
...@@ -7218,7 +7281,8 @@ var serviceContext = (function () { ...@@ -7218,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);
...@@ -7623,7 +7687,7 @@ var serviceContext = (function () { ...@@ -7623,7 +7687,7 @@ var serviceContext = (function () {
authResult: authResult, authResult: authResult,
errMsg: 'login:ok' errMsg: 'login:ok'
}); });
}, errorCallback, provider === 'apple' ? { scope: 'email' } : { univerifyStyle: params.univerifyStyle } || {}); }, errorCallback, provider === 'apple' ? { scope: 'email' } : { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) } || {});
} }
// 先注销再登录 // 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout // apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
...@@ -7691,6 +7755,12 @@ var serviceContext = (function () { ...@@ -7691,6 +7755,12 @@ var serviceContext = (function () {
}); });
}); });
} }
/**
* 获取用户信息-兼容
*/
function getUserProfile (params, callbackId) {
return getUserInfo(params, callbackId)
}
/** /**
* 获取用户信息 * 获取用户信息
...@@ -7714,7 +7784,30 @@ var serviceContext = (function () { ...@@ -7714,7 +7784,30 @@ var serviceContext = (function () {
} }
function closeAuthView () { function closeAuthView () {
getService('univerify').then(service => service.closeAuthView()); return getService('univerify').then(service => service.closeAuthView())
}
/**
* 一键登录自定义登陆按钮点击处理
*/
function univerifyButtonsClickHandling (univerifyStyle, errorCallback) {
if (univerifyStyle && isPlainObject(univerifyStyle) && univerifyStyle.buttons &&
Object.prototype.toString.call(univerifyStyle.buttons.list) === '[object Array]' &&
univerifyStyle.buttons.list.length > 0
) {
univerifyStyle.buttons.list.forEach((button, index) => {
univerifyStyle.buttons.list[index].onclick = function () {
closeAuthView().then(() => {
errorCallback({
code: '30008',
message: '用户点击了自定义按钮',
index
});
});
};
});
}
return univerifyStyle
} }
function requestPayment (params, callbackId) { function requestPayment (params, callbackId) {
...@@ -10778,7 +10871,6 @@ var serviceContext = (function () { ...@@ -10778,7 +10871,6 @@ var serviceContext = (function () {
ad.onLoad((e) => { ad.onLoad((e) => {
this._isLoaded = true; this._isLoaded = true;
this._isLoading = false; this._isLoading = false;
this._dispatchEvent(eventTypes.load, {});
if (this._loadPromiseResolve != null) { if (this._loadPromiseResolve != null) {
this._loadPromiseResolve(); this._loadPromiseResolve();
...@@ -10789,6 +10881,8 @@ var serviceContext = (function () { ...@@ -10789,6 +10881,8 @@ var serviceContext = (function () {
this._showPromiseResolve = null; this._showPromiseResolve = null;
this._showAd(); this._showAd();
} }
this._dispatchEvent(eventTypes.load, {});
}); });
ad.onClose((e) => { ad.onClose((e) => {
this._isLoaded = false; this._isLoaded = false;
...@@ -10811,17 +10905,17 @@ var serviceContext = (function () { ...@@ -10811,17 +10905,17 @@ var serviceContext = (function () {
this._dispatchEvent(eventTypes.error, data); this._dispatchEvent(eventTypes.error, data);
const promiseError = new Error(JSON.stringify(this._adError)); const error = new Error(JSON.stringify(this._adError));
promiseError.code = e.code; error.code = e.code;
promiseError.errMsg = e.message; error.errMsg = e.message;
if (this._loadPromiseReject != null) { if (this._loadPromiseReject != null) {
this._loadPromiseReject(promiseError); this._loadPromiseReject(error);
this._loadPromiseReject = null; this._loadPromiseReject = null;
} }
if (this._showPromiseReject != null) { if (this._showPromiseReject != null) {
this._showPromiseReject(promiseError); this._showPromiseReject(error);
this._showPromiseReject = null; this._showPromiseReject = null;
} }
}); });
...@@ -10906,7 +11000,7 @@ var serviceContext = (function () { ...@@ -10906,7 +11000,7 @@ var serviceContext = (function () {
constructor (options = {}) { constructor (options = {}) {
super(plus.ad.createInterstitialAd(options), options); super(plus.ad.createInterstitialAd(options), options);
this.load(); this._loadAd();
} }
} }
...@@ -10914,6 +11008,255 @@ var serviceContext = (function () { ...@@ -10914,6 +11008,255 @@ var serviceContext = (function () {
return new InterstitialAd(options) return new InterstitialAd(options)
} }
const sdkCache = {};
const sdkQueue = {};
function initSDK (options) {
const provider = options.provider;
if (!sdkCache[provider]) {
sdkCache[provider] = {};
}
if (typeof sdkCache[provider].plugin === 'object') {
options.success(sdkCache[provider].plugin);
return
}
if (!sdkQueue[provider]) {
sdkQueue[provider] = [];
}
sdkQueue[provider].push(options);
if (sdkCache[provider].status === true) {
options.__plugin = sdkCache[provider].plugin;
return
}
sdkCache[provider].status = 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].status = false;
return
}
// TODO
sdkCache[provider].plugin = plugin;
options.__plugin = plugin;
plugin.initSDK((res) => {
const isSuccess = (res.code === 1 || res.code === '1');
if (isSuccess) {
sdkCache[provider].plugin = plugin;
} else {
sdkCache[provider].status = 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._userData = options.userData;
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;
if (this._userData) {
this.bindUserData(this._userData);
}
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
});
}
}
bindUserData (data) {
if (this._ad !== null) {
this._ad.bindUserData(data);
}
}
_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;
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve();
this._loadPromiseResolve = null;
}
if (this._showPromiseResolve != null) {
this._showPromiseResolve();
this._showPromiseResolve = null;
this._showAd();
}
this._dispatchEvent(eventTypes.load, res);
}, (err) => {
this._isLoading = false;
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err));
this._showPromiseReject = null;
}
this._dispatchEvent(eventTypes.error, err);
});
}
}
_showAd () {
if (this._ad !== null && this._isLoaded === true) {
this._ad.show({
adpid: this._adpid
}, (res) => {
this._isLoaded = false;
}, (err) => {
this._isLoaded = false;
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err));
this._showPromiseReject = null;
}
this._dispatchEvent(eventTypes.error, err);
});
}
}
_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,
...@@ -11020,6 +11363,7 @@ var serviceContext = (function () { ...@@ -11020,6 +11363,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,
...@@ -11076,7 +11420,8 @@ var serviceContext = (function () { ...@@ -11076,7 +11420,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);
...@@ -22096,6 +22441,8 @@ var serviceContext = (function () { ...@@ -22096,6 +22441,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();
......
此差异已折叠。
{ {
"name": "@dcloudio/uni-app-plus", "name": "@dcloudio/uni-app-plus",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app app-plus", "description": "uni-app app-plus",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "app-plus", "name": "app-plus",
"title": "APP-PLUS" "title": "APP-PLUS"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-automator", "name": "@dcloudio/uni-automator",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app automator", "description": "uni-app automator",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -30,5 +30,5 @@ ...@@ -30,5 +30,5 @@
"node-simctl": "^6.1.0", "node-simctl": "^6.1.0",
"puppeteer": "^3.0.1" "puppeteer": "^3.0.1"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -314,7 +314,7 @@ export default { ...@@ -314,7 +314,7 @@ export default {
db = db.action(action) db = db.action(action)
} }
db.collection(this.collection).add(value).then((res) => { db.collection(this._getCollection()).add(value).then((res) => {
success && success(res) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
...@@ -388,7 +388,7 @@ export default { ...@@ -388,7 +388,7 @@ export default {
db = db.action(action) db = db.action(action)
} }
return db.collection(this.collection).doc(id).update(value).then((res) => { return db.collection(this._getCollection()).doc(id).update(value).then((res) => {
success && success(res) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
...@@ -546,7 +546,7 @@ export default { ...@@ -546,7 +546,7 @@ export default {
exec = exec.action(action) exec = exec.action(action)
} }
exec.collection(this.collection).where({ exec.collection(this._getCollection()).where({
_id: dbCmd.in(ids) _id: dbCmd.in(ids)
}).remove().then((res) => { }).remove().then((res) => {
success && success(res.result) success && success(res.result)
...@@ -570,6 +570,11 @@ export default { ...@@ -570,6 +570,11 @@ export default {
complete && complete() complete && complete()
}) })
}, },
_getCollection() {
const index = this.collection.indexOf(',')
const collection = index > 0 ? this.collection.substring(0, index) : this.collection
return collection
},
removeData (ids) { removeData (ids) {
const il = ids.slice(0) const il = ids.slice(0)
const dl = this.dataList const dl = this.dataList
......
{ {
"name": "@dcloudio/uni-cli-shared", "name": "@dcloudio/uni-cli-shared",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-cli-shared", "description": "uni-cli-shared",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
"postcss-urlrewrite": "^0.2.2", "postcss-urlrewrite": "^0.2.2",
"strip-json-comments": "^2.0.1" "strip-json-comments": "^2.0.1"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-h5-ui", "name": "@dcloudio/uni-h5-ui",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app h5 ui", "description": "uni-app h5 ui",
"main": "dist/index.umd.min.js", "main": "dist/index.umd.min.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
此差异已折叠。
{ {
"name": "@dcloudio/uni-h5", "name": "@dcloudio/uni-h5",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app h5", "description": "uni-app h5",
"main": "dist/index.umd.min.js", "main": "dist/index.umd.min.js",
"repository": { "repository": {
...@@ -25,5 +25,5 @@ ...@@ -25,5 +25,5 @@
"title": "H5", "title": "H5",
"main": "lib/h5/uni.config.js" "main": "lib/h5/uni.config.js"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-i18n", "name": "@dcloudio/uni-i18n",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "@dcloudio/uni-i18n", "description": "@dcloudio/uni-i18n",
"main": "dist/uni-i18n.cjs.js", "main": "dist/uni-i18n.cjs.js",
"module": "dist/uni-i18n.esm.js", "module": "dist/uni-i18n.esm.js",
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"bugs": { "bugs": {
"url": "https://github.com/dcloudio/uni-app/issues" "url": "https://github.com/dcloudio/uni-app/issues"
} },
"gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-migration", "name": "@dcloudio/uni-migration",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app migration", "description": "uni-app migration",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed", "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121",
"dependencies": { "dependencies": {
"commander": "^4.0.1", "commander": "^4.0.1",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
......
import Vue from 'vue'; import Vue from 'vue';
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 = ( my).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;
...@@ -930,6 +980,23 @@ const protocols = { // 需要做转换的 API 列表 ...@@ -930,6 +980,23 @@ const protocols = { // 需要做转换的 API 列表
}; };
} }
}, },
getUserProfile: {
name: my.canIUse('getOpenUserInfo') ? 'getOpenUserInfo' : 'getAuthUserInfo',
returnValue (result) {
if (my.canIUse('getOpenUserInfo')) {
let response = {};
try {
response = JSON.parse(result.response).response;
} catch (e) {}
result.nickName = response.nickName;
result.avatar = response.avatar;
}
result.userInfo = {
nickName: result.nickName,
avatarUrl: result.avatar
};
}
},
requestPayment: { requestPayment: {
name: 'tradePay', name: 'tradePay',
args: { args: {
...@@ -1982,6 +2049,7 @@ function parseBaseApp (vm, { ...@@ -1982,6 +2049,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-alipay"; Vue.prototype.mpHost = "mp-alipay";
......
{ {
"name": "@dcloudio/uni-mp-alipay", "name": "@dcloudio/uni-mp-alipay",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-alipay", "description": "uni-app mp-alipay",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-alipay", "name": "mp-alipay",
"title": "支付宝小程序" "title": "支付宝小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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 = ( swan).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;
...@@ -560,6 +610,13 @@ var getSystemInfo = { ...@@ -560,6 +610,13 @@ var getSystemInfo = {
} }
}; };
const oName = 'getUserInfo';
const nName = 'getUserProfile';
var getUserProfile = {
name: swan.canIUse(nName) ? nName : oName
};
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
'preloadPage', 'preloadPage',
...@@ -646,6 +703,7 @@ const protocols = { ...@@ -646,6 +703,7 @@ const protocols = {
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo,
getUserProfile,
getRecorderManager: { getRecorderManager: {
returnValue (fromRet) { returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded'); fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded');
...@@ -679,6 +737,9 @@ const protocols = { ...@@ -679,6 +737,9 @@ const protocols = {
getAccountInfoSync: { getAccountInfoSync: {
name: 'getEnvInfoSync', name: 'getEnvInfoSync',
returnValue: _handleEnvInfo returnValue: _handleEnvInfo
},
login: {
name: 'getLoginCode'
} }
}; };
...@@ -1675,6 +1736,7 @@ function parseBaseApp (vm, { ...@@ -1675,6 +1736,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-baidu"; Vue.prototype.mpHost = "mp-baidu";
......
{ {
"name": "@dcloudio/uni-mp-baidu", "name": "@dcloudio/uni-mp-baidu",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-baidu", "description": "uni-app mp-baidu",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-baidu", "name": "mp-baidu",
"title": "百度小程序" "title": "百度小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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 = ( ks).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;
...@@ -560,12 +610,20 @@ var getSystemInfo = { ...@@ -560,12 +610,20 @@ var getSystemInfo = {
} }
}; };
const oName = 'getUserInfo';
const nName = 'getUserProfile';
var getUserProfile = {
name: ks.canIUse(nName) ? nName : oName
};
const protocols = { const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo getSystemInfoSync: getSystemInfo,
getUserProfile
}; };
const todos = [ const todos = [
'vibrate' 'vibrate'
...@@ -1427,6 +1485,7 @@ function parseBaseApp (vm, { ...@@ -1427,6 +1485,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-kuaishou"; Vue.prototype.mpHost = "mp-kuaishou";
......
{ {
"name": "@dcloudio/uni-mp-kuaishou", "name": "@dcloudio/uni-mp-kuaishou",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-kuaishou", "description": "uni-app mp-kuaishou",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-kuaishou", "name": "mp-kuaishou",
"title": "快手小程序" "title": "快手小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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 = ( wx).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;
...@@ -560,12 +610,20 @@ var getSystemInfo = { ...@@ -560,12 +610,20 @@ var getSystemInfo = {
} }
}; };
const oName = 'getUserInfo';
const nName = 'getUserProfile';
var getUserProfile = {
name: wx.canIUse(nName) ? nName : oName
};
const protocols = { const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo getSystemInfoSync: getSystemInfo,
getUserProfile
}; };
const todos = [ const todos = [
'preloadPage', 'preloadPage',
...@@ -1588,6 +1646,7 @@ function parseBaseApp (vm, { ...@@ -1588,6 +1646,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-qq"; Vue.prototype.mpHost = "mp-qq";
......
{ {
"name": "@dcloudio/uni-mp-qq", "name": "@dcloudio/uni-mp-qq",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-qq", "description": "uni-app mp-qq",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-qq", "name": "mp-qq",
"title": "QQ小程序" "title": "QQ小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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 = ( tt).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;
...@@ -560,6 +610,13 @@ var getSystemInfo = { ...@@ -560,6 +610,13 @@ var getSystemInfo = {
} }
}; };
const oName = 'getUserInfo';
const nName = 'getUserProfile';
var getUserProfile = {
name: tt.canIUse(nName) ? nName : oName
};
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
'preloadPage', 'preloadPage',
...@@ -664,6 +721,7 @@ const protocols = { ...@@ -664,6 +721,7 @@ const protocols = {
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo,
getUserProfile,
connectSocket: { connectSocket: {
args: { args: {
method: false method: false
...@@ -1680,6 +1738,7 @@ function parseBaseApp (vm, { ...@@ -1680,6 +1738,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-toutiao"; Vue.prototype.mpHost = "mp-toutiao";
......
{ {
"name": "@dcloudio/uni-mp-toutiao", "name": "@dcloudio/uni-mp-toutiao",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-toutiao", "description": "uni-app mp-toutiao",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-toutiao", "name": "mp-toutiao",
"title": "字节跳动小程序" "title": "字节跳动小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-mp-vue", "name": "@dcloudio/uni-mp-vue",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "@dcloudio/uni-mp-vue", "description": "@dcloudio/uni-mp-vue",
"main": "dist/vue.runtime.esm.js", "main": "dist/vue.runtime.esm.js",
"module": "dist/vue.runtime.esm.js", "module": "dist/vue.runtime.esm.js",
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
"bugs": { "bugs": {
"url": "https://github.com/dcloudio/uni-app/issues" "url": "https://github.com/dcloudio/uni-app/issues"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
import Vue from 'vue'; import Vue from 'vue';
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 = ( wx).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;
...@@ -1345,6 +1395,7 @@ function parseBaseApp (vm, { ...@@ -1345,6 +1395,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-weixin"; Vue.prototype.mpHost = "mp-weixin";
......
{ {
"name": "@dcloudio/uni-mp-weixin", "name": "@dcloudio/uni-mp-weixin",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app mp-weixin", "description": "uni-app mp-weixin",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "mp-weixin", "name": "mp-weixin",
"title": "微信小程序" "title": "微信小程序"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-quickapp-native", "name": "@dcloudio/uni-quickapp-native",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app quickapp-native", "description": "uni-app quickapp-native",
"main": "dist/vue.prod.js", "main": "dist/vue.prod.js",
"repository": { "repository": {
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed", "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121",
"uni-app": { "uni-app": {
"name": "quickapp-native", "name": "quickapp-native",
"title": "快应用(Native)版" "title": "快应用(Native)版"
......
import Vue from 'vue'; import Vue from 'vue';
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 = ( qa).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;
...@@ -1350,6 +1400,7 @@ function parseBaseApp (vm, { ...@@ -1350,6 +1400,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "quickapp-webview"; Vue.prototype.mpHost = "quickapp-webview";
......
{ {
"name": "@dcloudio/uni-quickapp-webview", "name": "@dcloudio/uni-quickapp-webview",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app quickapp-webview", "description": "uni-app quickapp-webview",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
"name": "quickapp-webview", "name": "quickapp-webview",
"title": "快应用(Webview)版" "title": "快应用(Webview)版"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/uni-stat", "name": "@dcloudio/uni-stat",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"repository": { "repository": {
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
"rollup-plugin-replace": "^2.2.0", "rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2" "rollup-plugin-uglify": "^6.0.2"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -727,6 +727,16 @@ describe('mp:compiler-extra', () => { ...@@ -727,6 +727,16 @@ describe('mp:compiler-extra', () => {
'<block wx:for="{{[{x:[1,2,3,4]}]}}" wx:for-item="item" wx:for-index="index"><view><block wx:for="{{item.x}}" wx:for-item="item2" wx:for-index="__i0__"><view data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" data-event-params="{{({item2})}}" bindtap="__e">{{item2+"+"+index}}</view></block></view></block>', '<block wx:for="{{[{x:[1,2,3,4]}]}}" wx:for-item="item" wx:for-index="index"><view><block wx:for="{{item.x}}" wx:for-item="item2" wx:for-index="__i0__"><view data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" data-event-params="{{({item2})}}" bindtap="__e">{{item2+"+"+index}}</view></block></view></block>',
'with(this){if(!_isMounted){e0=function($event,item2){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item2=_temp2.item2;var _temp,_temp2;return test(item2)}}}' 'with(this){if(!_isMounted){e0=function($event,item2){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item2=_temp2.item2;var _temp,_temp2;return test(item2)}}}'
) )
assertCodegen(
'<view v-for="(item, index) in array()"><view @click="test"></view></view>',
'<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[\'tap\',[[\'test\',[\'$event\']]]]]}}" bindtap="__e"></view></view></block>',
'with(this){var l0=array();$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
assertCodegen(
'<view v-for="(item, index) in array()"><view @click="test(item)"></view></view>',
'<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" data-event-params="{{({item})}}" bindtap="__e"></view></view></block>',
'with(this){var l0=array();if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;return test(item)}}$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
}) })
it('generate bool attr', () => { it('generate bool attr', () => {
assertCodegen( assertCodegen(
......
...@@ -206,6 +206,22 @@ function isValuePath (path) { ...@@ -206,6 +206,22 @@ function isValuePath (path) {
return path.key !== 'key' && path.key !== 'id' && (path.key !== 'property' || path.parent.computed) && !(path.key === 'value' && path.parentPath.parentPath.isObjectPattern()) && !(path.key === 'left' && path.parentPath.parentPath.parentPath.isObjectPattern()) return path.key !== 'key' && path.key !== 'id' && (path.key !== 'property' || path.parent.computed) && !(path.key === 'value' && path.parentPath.parentPath.isObjectPattern()) && !(path.key === 'left' && path.parentPath.parentPath.parentPath.isObjectPattern())
} }
/**
* 判断 v-for 中是否包含复杂表达式:数组、对象、方法
*/
const isSafeScoped = (state) => {
const scopedArray = state.scoped
for (let index = 0; index < scopedArray.length; index++) {
const scoped = scopedArray[index]
const arrayExtra = scoped.forExtra[0].elements[0].value
// 简易判断
if (typeof arrayExtra === 'string' && (arrayExtra.startsWith('[') || arrayExtra.startsWith('{') || /\(.*\)/.test(arrayExtra))) {
return false
}
}
return true
}
function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false, tagName, ret) { function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false, tagName, ret) {
const key = keyPath.node const key = keyPath.node
let type = key.value || key.name || '' let type = key.value || key.name || ''
...@@ -304,18 +320,9 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false, ...@@ -304,18 +320,9 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
} }
} }
// 判断是否是复杂表达式 数组 或 对象 // 如果 v-for 遍历的值为 数组、对象、方法 则进入底部匿名表达式处理
const isNotDynamicExpression = (state) => { if (anonymous && isSafeScoped(state)) {
if (!(state.scoped[0])) { funcPath.traverse({
return true
}
const value = state.scoped[0].forExtra[0].elements[0].value
return !(typeof value === 'string' && (value.startsWith('[') || value.startsWith('}')))
}
// 如果v-for遍历的值为 数组、对象 则进入复杂表达式
if (isNotDynamicExpression(state)) {
anonymous && funcPath.traverse({
noScope: true, noScope: true,
MemberExpression (path) { MemberExpression (path) {
if (path.node.object.name === '$event' && path.node.property.name === if (path.node.object.name === '$event' && path.node.property.name ===
......
...@@ -30,5 +30,4 @@ module.exports = function getRenderSlot (path, state) { ...@@ -30,5 +30,4 @@ module.exports = function getRenderSlot (path, state) {
state.renderSlotStatementArray.push(t.expressionStatement(t.callExpression(t.identifier('$setScopedSlotsParams'), [t.stringLiteral(name.node.value), valueNode]))) state.renderSlotStatementArray.push(t.expressionStatement(t.callExpression(t.identifier('$setScopedSlotsParams'), [t.stringLiteral(name.node.value), valueNode])))
} }
// TODO 组件嵌套 // TODO 组件嵌套
path.skip()
} }
{ {
"name": "@dcloudio/uni-template-compiler", "name": "@dcloudio/uni-template-compiler",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-template-compiler", "description": "uni-template-compiler",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
"@babel/types": "^7.3.3", "@babel/types": "^7.3.3",
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.10"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/vue-cli-plugin-hbuilderx", "name": "@dcloudio/vue-cli-plugin-hbuilderx",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "HBuilderX plugin for vue-cli 3", "description": "HBuilderX plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
"css": "~2.2.1", "css": "~2.2.1",
"escodegen": "^1.8.1" "escodegen": "^1.8.1"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
{ {
"name": "@dcloudio/vue-cli-plugin-uni-optimize", "name": "@dcloudio/vue-cli-plugin-uni-optimize",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app optimize plugin for vue-cli 3", "description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -21,14 +21,14 @@ module.exports = (api, options) => { ...@@ -21,14 +21,14 @@ module.exports = (api, options) => {
'--host': `specify host (default: ${defaults.host})`, '--host': `specify host (default: ${defaults.host})`,
'--port': `specify port (default: ${defaults.port})`, '--port': `specify port (default: ${defaults.port})`,
'--https': `use https (default: ${defaults.https})`, '--https': `use https (default: ${defaults.https})`,
'--public': 'specify the public network URL for the HMR client', '--public': 'specify the public network URL for the HMR client',
'--auto-host': 'specify automator host', '--auto-host': 'specify automator host',
'--auto-port': 'specify automator port' '--auto-port': 'specify automator port'
} }
}, async function serve (args) { }, async function serve (args) {
info('Starting development server...') info('Starting development server...')
require('./util').initAutomator(args) require('./util').initAutomator(args)
// although this is primarily a dev server, it is possible that we // although this is primarily a dev server, it is possible that we
// are running it in a mode with a production env, e.g. in E2E tests. // are running it in a mode with a production env, e.g. in E2E tests.
...@@ -199,10 +199,10 @@ module.exports = (api, options) => { ...@@ -199,10 +199,10 @@ module.exports = (api, options) => {
}) })
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { const {
runByHBuilderX runByHBuilderX
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
// log instructions & open browser on first compilation complete // log instructions & open browser on first compilation complete
let isFirstCompile = true let isFirstCompile = true
compiler.hooks.done.tap('vue-cli-service uni-serve', stats => { compiler.hooks.done.tap('vue-cli-service uni-serve', stats => {
...@@ -224,9 +224,9 @@ module.exports = (api, options) => { ...@@ -224,9 +224,9 @@ module.exports = (api, options) => {
printRunningAt && console.log(' App running at:') printRunningAt && console.log(' App running at:')
printRunningAt && console.log( printRunningAt && console.log(
` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}` ` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}`
) )
if (!printRunningAt) { if (!printRunningAt) {
console.log('Build complete. Watching for changes...') console.log('Build complete. Watching for changes...')
} }
if (!isInContainer) { if (!isInContainer) {
printRunningAt && console.log(` - Network: ${chalk.cyan(networkUrl)}`) printRunningAt && console.log(` - Network: ${chalk.cyan(networkUrl)}`)
...@@ -260,11 +260,6 @@ module.exports = (api, options) => { ...@@ -260,11 +260,6 @@ module.exports = (api, options) => {
isFirstCompile = false isFirstCompile = false
if (!isProduction) { if (!isProduction) {
if (process.UNI_CLOUD) {
console.warn(
'当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
)
}
// const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : `npm run build` // const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : `npm run build`
// console.log(` Note that the development build is not optimized.`) // console.log(` Note that the development build is not optimized.`)
// console.log(` To create a production build, run ${chalk.cyan(buildCommand)}.`) // console.log(` To create a production build, run ${chalk.cyan(buildCommand)}.`)
...@@ -343,4 +338,4 @@ function checkInContainer () { ...@@ -343,4 +338,4 @@ function checkInContainer () {
module.exports.defaultModes = { module.exports.defaultModes = {
serve: 'development' serve: 'development'
} }
...@@ -96,6 +96,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { ...@@ -96,6 +96,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM), 'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER, 'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG, 'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG,
'process.env.RUN_BY_HBUILDERX': process.env.RUN_BY_HBUILDERX,
'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT) 'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT)
} }
if (process.env.UNI_USING_VUE3) { if (process.env.UNI_USING_VUE3) {
...@@ -138,4 +139,4 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { ...@@ -138,4 +139,4 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
webpackConfig.plugins.delete('progress') webpackConfig.plugins.delete('progress')
} }
} }
} }
...@@ -32,22 +32,38 @@ process.env.VUE_APP_NAME = manifestJsonObj.name ...@@ -32,22 +32,38 @@ process.env.VUE_APP_NAME = manifestJsonObj.name
process.env.UNI_USING_V3_SCOPED = true process.env.UNI_USING_V3_SCOPED = true
process.UNI_CLOUD = false
process.UNI_CLOUD_TCB = false
process.UNI_CLOUD_ALIYUN = false
process.env.UNI_CLOUD_PROVIDER = JSON.stringify([]) process.env.UNI_CLOUD_PROVIDER = JSON.stringify([])
const isH5 = !process.env.UNI_SUB_PLATFORM && process.env.UNI_PLATFORM === 'h5'
const isProduction = process.env.NODE_ENV === 'production'
if (process.env.UNI_CLOUD_SPACES) { if (process.env.UNI_CLOUD_SPACES) {
try { try {
const spaces = JSON.parse(process.env.UNI_CLOUD_SPACES) const spaces = JSON.parse(process.env.UNI_CLOUD_SPACES)
if (Array.isArray(spaces)) { if (Array.isArray(spaces)) {
process.UNI_CLOUD = spaces.length > 0 const hasUniCloudSpace = spaces.length > 0
process.UNI_CLOUD_TCB = !!spaces.find(space => !space.clientSecret)
process.UNI_CLOUD_ALIYUN = !!spaces.find(space => space.clientSecret)
if (spaces.length === 1) { if (spaces.length === 1) {
const space = spaces[0] const space = spaces[0]
console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`) console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`)
} }
if (
hasUniCloudSpace &&
isH5 &&
isProduction
) {
console.warn(
'发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5')
} else if (
hasUniCloudSpace &&
isH5 &&
!isProduction
) {
console.warn(
'当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
)
}
process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => { process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => {
if (space.clientSecret) { if (space.clientSecret) {
return { return {
...@@ -69,16 +85,6 @@ if (process.env.UNI_CLOUD_SPACES) { ...@@ -69,16 +85,6 @@ if (process.env.UNI_CLOUD_SPACES) {
} catch (e) {} } catch (e) {}
} }
if (
process.UNI_CLOUD &&
!process.env.UNI_SUB_PLATFORM &&
process.env.UNI_PLATFORM === 'h5' &&
process.env.NODE_ENV === 'production'
) {
console.warn(
'发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5')
}
// 初始化环境变量 // 初始化环境变量
const defaultOutputDir = '../../../../dist/' + const defaultOutputDir = '../../../../dist/' +
(process.env.NODE_ENV === 'production' ? 'build' : 'dev') + '/' + (process.env.NODE_ENV === 'production' ? 'build' : 'dev') + '/' +
...@@ -110,7 +116,9 @@ const { ...@@ -110,7 +116,9 @@ const {
isSupportSubPackages, isSupportSubPackages,
runByHBuilderX, runByHBuilderX,
getPagesJson getPagesJson
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
process.env.RUN_BY_HBUILDERX = JSON.stringify(runByHBuilderX)
const { const {
initUniModules initUniModules
......
...@@ -26,6 +26,7 @@ module.exports = function initOptions (options) { ...@@ -26,6 +26,7 @@ module.exports = function initOptions (options) {
// 增加 src/node_modules 解析 // 增加 src/node_modules 解析
options.transpileDependencies.push(genTranspileDepRegex(path.resolve(process.env.UNI_INPUT_DIR, 'node_modules'))) options.transpileDependencies.push(genTranspileDepRegex(path.resolve(process.env.UNI_INPUT_DIR, 'node_modules')))
options.transpileDependencies.push('@dcloudio/uni-' + process.env.UNI_PLATFORM) options.transpileDependencies.push('@dcloudio/uni-' + process.env.UNI_PLATFORM)
options.transpileDependencies.push('@dcloudio/uni-i18n')
options.transpileDependencies.push('@dcloudio/uni-stat') options.transpileDependencies.push('@dcloudio/uni-stat')
options.transpileDependencies.push('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud') options.transpileDependencies.push('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud')
...@@ -85,7 +86,7 @@ module.exports = function initOptions (options) { ...@@ -85,7 +86,7 @@ module.exports = function initOptions (options) {
if (sassLoaderVersion < 8) { if (sassLoaderVersion < 8) {
options.css.loaderOptions.sass.data = sassData options.css.loaderOptions.sass.data = sassData
} else { } else {
const name = sassLoaderVersion >= 9 ? 'additionalData' : 'prependData' const name = sassLoaderVersion >= 9 ? 'additionalData' : 'prependData'
options.css.loaderOptions.sass[name] = sassData options.css.loaderOptions.sass[name] = sassData
} }
......
{ {
"name": "@dcloudio/vue-cli-plugin-uni", "name": "@dcloudio/vue-cli-plugin-uni",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app plugin for vue-cli 3", "description": "uni-app plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@dcloudio/uni-stat": "^2.0.0-31920210422002", "@dcloudio/uni-stat": "^2.0.0-31920210609001",
"buffer-json": "^2.0.0", "buffer-json": "^2.0.0",
"copy-webpack-plugin": "^5.1.1", "copy-webpack-plugin": "^5.1.1",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
...@@ -37,5 +37,5 @@ ...@@ -37,5 +37,5 @@
"wrap-loader": "^0.2.0", "wrap-loader": "^0.2.0",
"xregexp": "4.0.0" "xregexp": "4.0.0"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -8,6 +8,11 @@ const trim_1 = __importDefault(require("./stylePlugins/trim")); ...@@ -8,6 +8,11 @@ const trim_1 = __importDefault(require("./stylePlugins/trim"));
const scoped_1 = __importDefault(require("./stylePlugins/scoped")); const scoped_1 = __importDefault(require("./stylePlugins/scoped"));
const styleProcessors_1 = require("./styleProcessors"); const styleProcessors_1 = require("./styleProcessors");
const removeScoped_1 = __importDefault(require("./stylePlugins/remove-scoped")); const removeScoped_1 = __importDefault(require("./stylePlugins/remove-scoped"));
let comments;
try{
comments = require('postcss-discard-comments')
}catch(e){}
function compileStyle(options) { function compileStyle(options) {
return doCompileStyle(Object.assign({}, options, { isAsync: false })); return doCompileStyle(Object.assign({}, options, { isAsync: false }));
} }
...@@ -31,6 +36,12 @@ function doCompileStyle(options) { ...@@ -31,6 +36,12 @@ function doCompileStyle(options) {
} else { // fixed by xxxxxx } else { // fixed by xxxxxx
plugins.push(removeScoped_1.default(id)); plugins.push(removeScoped_1.default(id));
} }
// fixed by xxxxxx
if (process.env.UNI_PLATFORM === 'app-plus' && process.env.NODE_ENV === 'production') {
if (comments) {
plugins.push(comments);
}
}
const postCSSOptions = Object.assign({}, postcssOptions, { to: filename, from: filename }); const postCSSOptions = Object.assign({}, postcssOptions, { to: filename, from: filename });
if (map) { if (map) {
postCSSOptions.map = { postCSSOptions.map = {
......
{ {
"name": "@dcloudio/webpack-uni-mp-loader", "name": "@dcloudio/webpack-uni-mp-loader",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "webpack-uni-mp-loader", "description": "webpack-uni-mp-loader",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
}, },
"author": "fxy060608", "author": "fxy060608",
"license": "Apache-2.0", "license": "Apache-2.0",
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -12,6 +12,10 @@ const { ...@@ -12,6 +12,10 @@ const {
parseTabBar parseTabBar
} = require('../util') } = require('../util')
function defaultCopy (name, value, json) {
json[name] = value
}
const pagesJson2AppJson = { const pagesJson2AppJson = {
globalStyle: function (name, value, json) { globalStyle: function (name, value, json) {
json.window = parseStyle(value) json.window = parseStyle(value)
...@@ -22,7 +26,8 @@ const pagesJson2AppJson = { ...@@ -22,7 +26,8 @@ const pagesJson2AppJson = {
}, },
tabBar: function (name, value, json) { tabBar: function (name, value, json) {
json.tabBar = parseTabBar(value) json.tabBar = parseTabBar(value)
} },
preloadRule: defaultCopy
} }
function copyToJson (json, fromJson, options) { function copyToJson (json, fromJson, options) {
...@@ -62,19 +67,19 @@ module.exports = function (pagesJson, manifestJson) { ...@@ -62,19 +67,19 @@ module.exports = function (pagesJson, manifestJson) {
app.subPackages.push(subPackages[root]) app.subPackages.push(subPackages[root])
}) })
copyToJson(app, pagesJson, pagesJson2AppJson) copyToJson(app, pagesJson, pagesJson2AppJson)
const platformJson = manifestJson['mp-alipay'] || {} const platformJson = manifestJson['mp-alipay'] || {}
if (hasOwn(platformJson, 'plugins')) { if (hasOwn(platformJson, 'plugins')) {
app.plugins = platformJson.plugins app.plugins = platformJson.plugins
} }
if (app.usingComponents) { if (app.usingComponents) {
updateAppJsonUsingComponents(app.usingComponents) updateAppJsonUsingComponents(app.usingComponents)
} }
const project = Object.assign({}, manifestJson['mp-alipay'] || {}) const project = Object.assign({}, manifestJson['mp-alipay'] || {})
delete project.usingComponents delete project.usingComponents
delete project.plugins delete project.plugins
return [{ return [{
...@@ -84,4 +89,4 @@ module.exports = function (pagesJson, manifestJson) { ...@@ -84,4 +89,4 @@ module.exports = function (pagesJson, manifestJson) {
name: 'mini.project', name: 'mini.project',
content: project content: project
}] }]
} }
{ {
"name": "@dcloudio/webpack-uni-pages-loader", "name": "@dcloudio/webpack-uni-pages-loader",
"version": "2.0.0-31920210422002", "version": "2.0.0-31920210609001",
"description": "uni-app pages.json loader", "description": "uni-app pages.json loader",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"strip-json-comments": "^2.0.1" "strip-json-comments": "^2.0.1"
}, },
"uni-app": { "uni-app": {
"compilerVersion": "3.1.11" "compilerVersion": "3.1.18"
}, },
"gitHead": "b366367ac0b63f41ef205dc93eee55d8e9f8f3ed" "gitHead": "2033cd540cff5d8469ff77e87779cd4daa5c9121"
} }
...@@ -45,7 +45,7 @@ export function getTargetDataset (target) { ...@@ -45,7 +45,7 @@ export function getTargetDataset (target) {
const $attrs = vm.$attrs const $attrs = vm.$attrs
for (const key in $attrs) { for (const key in $attrs) {
if (key.startsWith('data-')) { if (key.startsWith('data-')) {
const newKey = camelize(key.substr(5)) const newKey = camelize(key.substr(5).toLowerCase())
const value = $attrs[key] const value = $attrs[key]
dataset[newKey] = force ? value : dataset[newKey] || value dataset[newKey] = force ? value : dataset[newKey] || value
} }
......
...@@ -24,6 +24,10 @@ import { ...@@ -24,6 +24,10 @@ import {
getTabBarScrollPosition getTabBarScrollPosition
} from './app/router-guard' } from './app/router-guard'
import {
uniIdMixin
} from 'uni-shared'
function getMinId (routes) { function getMinId (routes) {
let minId = 0 let minId = 0
routes.forEach(route => { routes.forEach(route => {
...@@ -74,6 +78,8 @@ export default { ...@@ -74,6 +78,8 @@ export default {
lifecycleMixin(Vue) lifecycleMixin(Vue)
uniIdMixin(Vue)
/* eslint-disable no-undef */ /* eslint-disable no-undef */
if (typeof __UNI_ROUTER_BASE__ !== 'undefined') { if (typeof __UNI_ROUTER_BASE__ !== 'undefined') {
__uniConfig.router.base = __UNI_ROUTER_BASE__ __uniConfig.router.base = __UNI_ROUTER_BASE__
......
...@@ -196,9 +196,9 @@ export default { ...@@ -196,9 +196,9 @@ export default {
img.src = realImagePath img.src = realImagePath
} else { } else {
this._clearImage() this._clearImage()
this._resetData()
// 与微信小程序保持一致,保留之前样式 // 与微信小程序保持一致,保留之前样式
// this._resetData() // this._resetSize()
this._resetSize()
} }
}, },
_clearImage () { _clearImage () {
......
<template> <template>
<uni-progress <uni-progress
class="uni-progress" class="uni-progress"
v-on="$listeners" v-on="$listeners"
> >
<div <div
:style="outerBarStyle" :style="outerBarStyle"
class="uni-progress-bar" class="uni-progress-bar"
> >
<div <div
:style="innerBarStyle" :style="innerBarStyle"
class="uni-progress-inner-bar" class="uni-progress-inner-bar"
/> />
</div> </div>
<template v-if="showInfo"> <template v-if="showInfo">
<p class="uni-progress-info"> <p class="uni-progress-info">
{{ currentPercent }}% {{ currentPercent }}%
</p> </p>
</template> </template>
</uni-progress> </uni-progress>
...@@ -65,6 +65,13 @@ export default { ...@@ -65,6 +65,13 @@ export default {
activeMode: { activeMode: {
type: String, type: String,
default: VALUES.activeMode default: VALUES.activeMode
},
duration: {
type: [Number, String],
default: 30,
validator (value) {
return !isNaN(parseFloat(value, 10))
}
} }
}, },
data () { data () {
...@@ -117,7 +124,7 @@ export default { ...@@ -117,7 +124,7 @@ export default {
} else { } else {
this.currentPercent += 1 this.currentPercent += 1
} }
}, 30) }, parseFloat(this.duration))
} else { } else {
this.currentPercent = this.realPercent this.currentPercent = this.realPercent
} }
...@@ -154,4 +161,4 @@ export default { ...@@ -154,4 +161,4 @@ export default {
margin-left: 15px; margin-left: 15px;
font-size: 16px; font-size: 16px;
} }
</style> </style>
...@@ -253,7 +253,7 @@ export default { ...@@ -253,7 +253,7 @@ export default {
_onTrack: function (e) { _onTrack: function (e) {
if (!this.disabled) { if (!this.disabled) {
return e.detail.state === 'move' ? (this._onUserChangedValue({ return e.detail.state === 'move' ? (this._onUserChangedValue({
x: e.detail.x0 x: e.detail.x
}), this.$trigger('changing', e, { }), this.$trigger('changing', e, {
value: this.sliderValue value: this.sliderValue
}), !1) : (e.detail.state === 'end' && this.$trigger('change', e, { }), !1) : (e.detail.state === 'end' && this.$trigger('change', e, {
......
<template> <template>
<uni-textarea v-on="$listeners"> <uni-textarea v-on="$listeners">
<div class="uni-textarea-wrapper"> <div
ref="wrapper"
class="uni-textarea-wrapper"
>
<div <div
v-show="!(composing || valueSync.length)" v-show="!(composing || valueSync.length)"
ref="placeholder" ref="placeholder"
...@@ -144,7 +147,8 @@ export default { ...@@ -144,7 +147,8 @@ export default {
lineCount lineCount
}) })
if (this.autoHeight) { if (this.autoHeight) {
this.$el.style.height = this.height + 'px' this.$el.style.height = 'auto'
this.$refs.wrapper.style.height = this.height + 'px'
} }
} }
}, },
...@@ -246,7 +250,6 @@ uni-textarea { ...@@ -246,7 +250,6 @@ uni-textarea {
line-height: normal; line-height: normal;
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-all; word-break: break-all;
box-sizing: content-box !important;
} }
uni-textarea[hidden] { uni-textarea[hidden] {
display: none; display: none;
......
...@@ -194,20 +194,31 @@ export default { ...@@ -194,20 +194,31 @@ export default {
this._onInput($event, true) this._onInput($event, true)
} }
this.focusSync = false this.focusSync = false
const field = $event.target
let cursor
if (field.type === 'number') {
field.type = 'text'
cursor = field.selectionEnd
field.type = 'number'
} else {
cursor = field.selectionEnd
}
this.$trigger('blur', $event, { this.$trigger('blur', $event, {
value: this.valueSync, value: this.valueSync,
cursor: $event.target.selectionEnd cursor
}) })
}, },
_checkSelection () { _checkSelection () {
if (this.focusSync && this.selectionStartNumber > -1 && this.selectionEndNumber > -1) { const field = this._field
this._field.selectionStart = this.selectionStartNumber if (this.focusSync && this.selectionStartNumber > -1 && this.selectionEndNumber > -1 && field.type !== 'number') {
this._field.selectionEnd = this.selectionEndNumber field.selectionStart = this.selectionStartNumber
field.selectionEnd = this.selectionEndNumber
} }
}, },
_checkCursor () { _checkCursor () {
if (this.focusSync && this.selectionStartNumber < 0 && this.selectionEndNumber < 0 && this.cursorNumber > -1) { const field = this._field
this._field.selectionEnd = this._field.selectionStart = this.cursorNumber if (this.focusSync && this.selectionStartNumber < 0 && this.selectionEndNumber < 0 && this.cursorNumber > -1 && field.type !== 'number') {
field.selectionEnd = field.selectionStart = this.cursorNumber
} }
} }
} }
......
...@@ -35,8 +35,8 @@ export default { ...@@ -35,8 +35,8 @@ export default {
changedTouches: $event.changedTouches, changedTouches: $event.changedTouches,
detail: { detail: {
state, state,
x0: x, x: x,
y0: y, y: y,
dx: x - x0, dx: x - x0,
dy: y - y0, dy: y - y0,
ddx: x - x1, ddx: x - x1,
......
...@@ -22,10 +22,13 @@ function addBase (filePath) { ...@@ -22,10 +22,13 @@ function addBase (filePath) {
export default function getRealPath (filePath) { export default function getRealPath (filePath) {
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath return 'https:' + filePath
} else {
return addBase(filePath.substr(1))
} }
// 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
}
return addBase(filePath.substr(1))
} }
// 网络资源或base64 // 网络资源或base64
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) { if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
...@@ -43,4 +46,4 @@ export default function getRealPath (filePath) { ...@@ -43,4 +46,4 @@ export default function getRealPath (filePath) {
} }
return filePath return filePath
} }
...@@ -37,7 +37,6 @@ class AdBase { ...@@ -37,7 +37,6 @@ class AdBase {
ad.onLoad((e) => { ad.onLoad((e) => {
this._isLoaded = true this._isLoaded = true
this._isLoading = false this._isLoading = false
this._dispatchEvent(eventTypes.load, {})
if (this._loadPromiseResolve != null) { if (this._loadPromiseResolve != null) {
this._loadPromiseResolve() this._loadPromiseResolve()
...@@ -48,6 +47,8 @@ class AdBase { ...@@ -48,6 +47,8 @@ class AdBase {
this._showPromiseResolve = null this._showPromiseResolve = null
this._showAd() this._showAd()
} }
this._dispatchEvent(eventTypes.load, {})
}) })
ad.onClose((e) => { ad.onClose((e) => {
this._isLoaded = false this._isLoaded = false
...@@ -70,17 +71,17 @@ class AdBase { ...@@ -70,17 +71,17 @@ class AdBase {
this._dispatchEvent(eventTypes.error, data) this._dispatchEvent(eventTypes.error, data)
const promiseError = new Error(JSON.stringify(this._adError)) const error = new Error(JSON.stringify(this._adError))
promiseError.code = e.code error.code = e.code
promiseError.errMsg = e.message error.errMsg = e.message
if (this._loadPromiseReject != null) { if (this._loadPromiseReject != null) {
this._loadPromiseReject(promiseError) this._loadPromiseReject(error)
this._loadPromiseReject = null this._loadPromiseReject = null
} }
if (this._showPromiseReject != null) { if (this._showPromiseReject != null) {
this._showPromiseReject(promiseError) this._showPromiseReject(error)
this._showPromiseReject = null this._showPromiseReject = null
} }
}) })
...@@ -152,5 +153,7 @@ class AdBase { ...@@ -152,5 +153,7 @@ class AdBase {
} }
export { export {
eventTypes,
eventNames,
AdBase AdBase
} }
import {
requireNativePlugin
} from '../../bridge'
import {
eventTypes,
eventNames
} from './ad-base.js'
const sdkCache = {}
const sdkQueue = {}
function initSDK (options) {
const provider = options.provider
if (!sdkCache[provider]) {
sdkCache[provider] = {}
}
if (typeof sdkCache[provider].plugin === 'object') {
options.success(sdkCache[provider].plugin)
return
}
if (!sdkQueue[provider]) {
sdkQueue[provider] = []
}
sdkQueue[provider].push(options)
if (sdkCache[provider].status === true) {
options.__plugin = sdkCache[provider].plugin
return
}
sdkCache[provider].status = 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].status = false
return
}
// TODO
sdkCache[provider].plugin = plugin
options.__plugin = plugin
plugin.initSDK((res) => {
const isSuccess = (res.code === 1 || res.code === '1')
if (isSuccess) {
sdkCache[provider].plugin = plugin
} else {
sdkCache[provider].status = 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.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._userData = options.userData
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
if (this._userData) {
this.bindUserData(this._userData)
}
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
})
}
}
bindUserData (data) {
if (this._ad !== null) {
this._ad.bindUserData(data)
}
}
_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
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve()
this._loadPromiseResolve = null
}
if (this._showPromiseResolve != null) {
this._showPromiseResolve()
this._showPromiseResolve = null
this._showAd()
}
this._dispatchEvent(eventTypes.load, res)
}, (err) => {
this._isLoading = false
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err))
this._showPromiseReject = null
}
this._dispatchEvent(eventTypes.error, err)
})
}
}
_showAd () {
if (this._ad !== null && this._isLoaded === true) {
this._ad.show({
adpid: this._adpid
}, (res) => {
this._isLoaded = false
}, (err) => {
this._isLoaded = false
if (this._showPromiseReject != null) {
this._showPromiseReject(this._createError(err))
this._showPromiseReject = null
}
this._dispatchEvent(eventTypes.error, err)
})
}
}
_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 || {})
}
})
}
}
export function createInteractiveAd (options) {
if (!options.provider) {
return new Error('provider invalid')
}
if (!options.adpid) {
return new Error('adpid invalid')
}
return new InteractiveAd(options)
}
...@@ -6,7 +6,7 @@ class InterstitialAd extends AdBase { ...@@ -6,7 +6,7 @@ class InterstitialAd extends AdBase {
constructor (options = {}) { constructor (options = {}) {
super(plus.ad.createInterstitialAd(options), options) super(plus.ad.createInterstitialAd(options), options)
this.load() this._loadAd()
} }
} }
......
...@@ -82,3 +82,4 @@ export * from './ad/ad' ...@@ -82,3 +82,4 @@ export * from './ad/ad'
export * from './ad/rewarded-video-ad' export * from './ad/rewarded-video-ad'
export * from './ad/full-screen-video-ad' export * from './ad/full-screen-video-ad'
export * from './ad/interstitial-ad' export * from './ad/interstitial-ad'
export * from './ad/interactive-ad'
...@@ -34,7 +34,7 @@ export function chooseVideo ({ ...@@ -34,7 +34,7 @@ export function chooseVideo ({
}, () => { }, () => {
resolve(tempFilePath) resolve(tempFilePath)
}) })
}) : Promise.resolve() }) : Promise.resolve(tempFilePath)
if (compressed) { if (compressed) {
plus.nativeUI.showWaiting() plus.nativeUI.showWaiting()
} }
...@@ -55,7 +55,7 @@ export function chooseVideo ({ ...@@ -55,7 +55,7 @@ export function chooseVideo ({
result.height = videoInfo.height result.height = videoInfo.height
invoke(callbackId, result) invoke(callbackId, result)
}, },
errorCallback fail: errorCallback
}) })
}) })
} }
......
...@@ -7,10 +7,13 @@ export const getVideoInfo = warpPlusMethod('io', 'getVideoInfo', options => { ...@@ -7,10 +7,13 @@ export const getVideoInfo = warpPlusMethod('io', 'getVideoInfo', options => {
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
} }
}) })
...@@ -46,6 +46,7 @@ export function createRequestTaskById (requestTaskId, { ...@@ -46,6 +46,7 @@ export function createRequestTaskById (requestTaskId, {
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')
...@@ -99,7 +100,8 @@ export function createRequestTaskById (requestTaskId, { ...@@ -99,7 +100,8 @@ export function createRequestTaskById (requestTaskId, {
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)
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
warpPlusSuccessCallback, warpPlusSuccessCallback,
warpPlusErrorCallback warpPlusErrorCallback
} from '../util' } from '../util'
import { isPlainObject } from 'uni-shared'
function getService (provider) { function getService (provider) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -31,7 +32,7 @@ export function login (params, callbackId) { ...@@ -31,7 +32,7 @@ export function login (params, callbackId) {
authResult: authResult, authResult: authResult,
errMsg: 'login:ok' errMsg: 'login:ok'
}) })
}, errorCallback, provider === 'apple' ? { scope: 'email' } : { univerifyStyle: params.univerifyStyle } || {}) }, errorCallback, provider === 'apple' ? { scope: 'email' } : { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) } || {})
} }
// 先注销再登录 // 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout // apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
...@@ -99,6 +100,12 @@ export function getUserInfo (params, callbackId) { ...@@ -99,6 +100,12 @@ export function getUserInfo (params, callbackId) {
}) })
}) })
} }
/**
* 获取用户信息-兼容
*/
export function getUserProfile (params, callbackId) {
return getUserInfo(params, callbackId)
}
/** /**
* 获取用户信息 * 获取用户信息
...@@ -122,5 +129,28 @@ export function preLogin (params, callbackId) { ...@@ -122,5 +129,28 @@ export function preLogin (params, callbackId) {
} }
export function closeAuthView () { export function closeAuthView () {
getService('univerify').then(service => service.closeAuthView()) return getService('univerify').then(service => service.closeAuthView())
}
/**
* 一键登录自定义登陆按钮点击处理
*/
function univerifyButtonsClickHandling (univerifyStyle, errorCallback) {
if (univerifyStyle && isPlainObject(univerifyStyle) && univerifyStyle.buttons &&
Object.prototype.toString.call(univerifyStyle.buttons.list) === '[object Array]' &&
univerifyStyle.buttons.list.length > 0
) {
univerifyStyle.buttons.list.forEach((button, index) => {
univerifyStyle.buttons.list[index].onclick = function () {
closeAuthView().then(() => {
errorCallback({
code: '30008',
message: '用户点击了自定义按钮',
index
})
})
}
})
}
return univerifyStyle
} }
...@@ -60,7 +60,7 @@ export function getRealPath (filePath) { ...@@ -60,7 +60,7 @@ export function getRealPath (filePath) {
// 无协议的情况补全 https // 无协议的情况补全 https
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath return 'https:' + filePath
} }
// 网络资源或base64 // 网络资源或base64
...@@ -75,6 +75,10 @@ export function getRealPath (filePath) { ...@@ -75,6 +75,10 @@ export function getRealPath (filePath) {
const wwwPath = 'file://' + _handleLocalPath('_www') const wwwPath = 'file://' + _handleLocalPath('_www')
// 绝对路径转换为本地文件系统路径 // 绝对路径转换为本地文件系统路径
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
// 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
}
return wwwPath + filePath return wwwPath + filePath
} }
// 相对资源 // 相对资源
......
...@@ -22,6 +22,10 @@ import { ...@@ -22,6 +22,10 @@ import {
vdSyncCallbacks vdSyncCallbacks
} from '../subscribe-handlers/on-vd-sync-callback' } from '../subscribe-handlers/on-vd-sync-callback'
import {
uniIdMixin
} from 'uni-shared'
export default { export default {
install (Vue, options) { install (Vue, options) {
initVue(Vue) initVue(Vue)
...@@ -31,6 +35,8 @@ export default { ...@@ -31,6 +35,8 @@ export default {
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()
...@@ -94,4 +100,4 @@ export default { ...@@ -94,4 +100,4 @@ export default {
return callback ? undefined : result return callback ? undefined : result
} }
} }
} }
...@@ -143,9 +143,6 @@ export default { ...@@ -143,9 +143,6 @@ export default {
} }
}) })
}, },
beforeDestroy () {
window.removeEventListener('message', this.__messageHandle, false)
},
methods: { methods: {
_choose () { _choose () {
if (this.selected) { if (this.selected) {
......
...@@ -23,10 +23,11 @@ const passiveOptions = supportsPassive ? { ...@@ -23,10 +23,11 @@ const passiveOptions = supportsPassive ? {
function updateCssVar (vm) { function updateCssVar (vm) {
if (uni.canIUse('css.var')) { if (uni.canIUse('css.var')) {
const uniConfigTabbarHeight = parseFloat(__uniConfig.tabBar.height)
const pageVm = vm.$parent.$parent const pageVm = vm.$parent.$parent
const navigationBarType = pageVm.navigationBar.type const navigationBarType = pageVm.navigationBar.type
const windowTopValue = navigationBarType === 'default' || navigationBarType === 'float' ? NAVBAR_HEIGHT : 0 const windowTopValue = navigationBarType === 'default' || navigationBarType === 'float' ? NAVBAR_HEIGHT : 0
const windowBottomValue = getApp().$children[0].showTabBar ? TABBAR_HEIGHT : 0 const windowBottomValue = getApp().$children[0].showTabBar ? isNaN(uniConfigTabbarHeight) ? TABBAR_HEIGHT : uniConfigTabbarHeight : 0
const envMethod = uni.canIUse('css.env') ? 'env' : (uni.canIUse('css.constant') ? 'constant' : '') const envMethod = uni.canIUse('css.env') ? 'env' : (uni.canIUse('css.constant') ? 'constant' : '')
const windowTop = windowTopValue && envMethod ? `calc(${windowTopValue}px + ${envMethod}(safe-area-inset-top))` const windowTop = windowTopValue && envMethod ? `calc(${windowTopValue}px + ${envMethod}(safe-area-inset-top))`
: `${windowTopValue}px` : `${windowTopValue}px`
...@@ -87,4 +88,4 @@ export default function initSubscribe (subscribe) { ...@@ -87,4 +88,4 @@ export default function initSubscribe (subscribe) {
}) })
} }
}) })
} }
...@@ -364,7 +364,7 @@ export default { ...@@ -364,7 +364,7 @@ export default {
} }
const danmuList = this.otherData.danmuList = JSON.parse(JSON.stringify(this.danmuList || [])) const danmuList = this.otherData.danmuList = JSON.parse(JSON.stringify(this.danmuList || []))
danmuList.sort(function (a, b) { danmuList.sort(function (a, b) {
return (a.time || 0) - (a.time || 0) return (a.time || 0) - (b.time || 0)
}) })
}, },
mounted () { mounted () {
......
...@@ -381,6 +381,23 @@ const protocols = { // 需要做转换的 API 列表 ...@@ -381,6 +381,23 @@ const protocols = { // 需要做转换的 API 列表
} }
} }
}, },
getUserProfile: {
name: my.canIUse('getOpenUserInfo') ? 'getOpenUserInfo' : 'getAuthUserInfo',
returnValue (result) {
if (my.canIUse('getOpenUserInfo')) {
let response = {}
try {
response = JSON.parse(result.response).response
} catch (e) {}
result.nickName = response.nickName
result.avatar = response.avatar
}
result.userInfo = {
nickName: result.nickName,
avatarUrl: result.avatar
}
}
},
requestPayment: { requestPayment: {
name: 'tradePay', name: 'tradePay',
args: { args: {
......
...@@ -2,6 +2,7 @@ import navigateTo from 'uni-helpers/navigate-to' ...@@ -2,6 +2,7 @@ import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
...@@ -89,6 +90,7 @@ const protocols = { ...@@ -89,6 +90,7 @@ const protocols = {
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo,
getUserProfile,
getRecorderManager: { getRecorderManager: {
returnValue (fromRet) { returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded') fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded')
...@@ -122,6 +124,9 @@ const protocols = { ...@@ -122,6 +124,9 @@ const protocols = {
getAccountInfoSync: { getAccountInfoSync: {
name: 'getEnvInfoSync', name: 'getEnvInfoSync',
returnValue: _handleEnvInfo returnValue: _handleEnvInfo
},
login: {
name: 'getLoginCode'
} }
} }
......
...@@ -2,13 +2,15 @@ import navigateTo from 'uni-helpers/navigate-to' ...@@ -2,13 +2,15 @@ import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo getSystemInfoSync: getSystemInfo,
getUserProfile
} }
export const todos = [ export const todos = [
'vibrate' 'vibrate'
......
...@@ -2,13 +2,15 @@ import navigateTo from 'uni-helpers/navigate-to' ...@@ -2,13 +2,15 @@ import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo getSystemInfoSync: getSystemInfo,
getUserProfile
} }
export const todos = [ export const todos = [
'preloadPage', 'preloadPage',
......
...@@ -2,6 +2,7 @@ import navigateTo from 'uni-helpers/navigate-to' ...@@ -2,6 +2,7 @@ import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 不支持的 API 列表 // 不支持的 API 列表
const todos = [ const todos = [
...@@ -107,6 +108,7 @@ const protocols = { ...@@ -107,6 +108,7 @@ const protocols = {
previewImage, previewImage,
getSystemInfo, getSystemInfo,
getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo,
getUserProfile,
connectSocket: { connectSocket: {
args: { args: {
method: false method: false
......
const oName = 'getUserInfo'
const nName = 'getUserProfile'
export default {
name: __GLOBAL__.canIUse(nName) ? nName : oName
}
...@@ -11,6 +11,10 @@ import { ...@@ -11,6 +11,10 @@ import {
getEventChannel getEventChannel
} from 'uni-helpers/navigate-to' } from 'uni-helpers/navigate-to'
import {
uniIdMixin
} from 'uni-shared'
const hooks = [ const hooks = [
'onShow', 'onShow',
'onHide', 'onHide',
...@@ -101,6 +105,7 @@ export default function parseBaseApp (vm, { ...@@ -101,6 +105,7 @@ export default function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store Vue.prototype.$store = vm.$options.store
} }
uniIdMixin(Vue)
Vue.prototype.mpHost = __PLATFORM__ Vue.prototype.mpHost = __PLATFORM__
......
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 = (__PLATFORM__ === 'h5' || __PLATFORM__ === 'app-plus' ? uni : __GLOBAL__).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
}
export 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()
}
}
...@@ -193,3 +193,5 @@ export function deepClone (vnodes, createElement) { ...@@ -193,3 +193,5 @@ export function deepClone (vnodes, createElement) {
return vnodes.map(cloneVNode) return vnodes.map(cloneVNode)
} }
export * from './uni-id-mixin'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册