@mpxjs/api-proxy
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "@mpxjs/api-proxy", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "convert miniprogram API at each end", | ||
@@ -5,0 +5,0 @@ "module": "src/index.js", |
@@ -33,4 +33,51 @@ # mpx-api-proxy | ||
## example | ||
#### 普通形式 | ||
```js | ||
import mpx from '@mpxjs/core' | ||
import apiProxy from '@mpxjs/api-proxy' | ||
mpx.use(apiProxy, { | ||
exclude: ['showToast'] // showToast 将不会被转换为目标平台 | ||
}) | ||
mpx.showModal({ | ||
title: '标题', | ||
content: '这是一个弹窗', | ||
success (res) { | ||
if (res.cancel) { | ||
console.log('用户点击取消') | ||
} | ||
} | ||
}) | ||
``` | ||
#### 使用 promise 形式 | ||
```js | ||
import mpx from '@mpxjs/core' | ||
import apiProxy from '@mpxjs/api-proxy' | ||
mpx.use(apiProxy, { | ||
usePromise: true, | ||
whiteList: ['showToast'] // showToast 将不能使用 promise 形式 | ||
}) | ||
wx.showActionSheet({ | ||
itemList: ['A', 'B', 'C'] | ||
}) | ||
.then(res => { | ||
console.log(res.tapIndex) | ||
}) | ||
.catch(err => { | ||
console.log(err) | ||
}) | ||
``` | ||
## Done | ||
* ⚔ **微信 → 支付宝** | ||
* ⚔ **百度 → 支付宝** | ||
* ⚔ **QQ → 支付宝** |
@@ -614,39 +614,29 @@ import { changeOpts, handleSuccess, getEnvObj, error, warn, noop } from '../utils' | ||
createSelectorQuery (options = {}) { | ||
let query = ALI_OBJ.createSelectorQuery(options) | ||
let cbs = [] | ||
const selectorQuery = ALI_OBJ.createSelectorQuery(options) | ||
const proxyMethods = ['boundingClientRect', 'scrollOffset'] | ||
const cbs = [] | ||
proxyMethods.forEach((name) => { | ||
const originalMethod = selectorQuery[name] | ||
selectorQuery[name] = function (cb = noop) { | ||
cbs.push(cb) | ||
return originalMethod.call(this) | ||
} | ||
}) | ||
if (query) { | ||
const apiArr = ['select', 'selectAll', 'selectViewport'] | ||
const cacheExec = query.exec || noop | ||
apiArr.forEach(key => { | ||
const cacheKey = query[key] || noop | ||
query[key] = dom => { | ||
const selected = cacheKey.call(query, dom) | ||
const cacheBoundingClientRect = selected.boundingClientRect | ||
selected.boundingClientRect = (...args) => { | ||
if (typeof args[0] === 'function') { | ||
cbs.push(args[0]) | ||
// error('请将 boundingClientRect 中的回调函数放入 exec 中使用') | ||
} | ||
return cacheBoundingClientRect.call(selected) | ||
} | ||
return selected | ||
} | ||
}) | ||
query.exec = (fn = noop) => { | ||
return cacheExec.call(query, res => { | ||
cbs.forEach((cb, idx) => { | ||
cb.call(this, res[idx]) | ||
}) | ||
cbs = [] | ||
fn.call(this, res) | ||
const originalExec = selectorQuery.exec | ||
selectorQuery.exec = function (originalCb = noop) { | ||
const cb = function (results) { | ||
results.forEach((item, index) => { | ||
cbs[index](item) | ||
}) | ||
originalCb(results) | ||
} | ||
return originalExec.call(this, cb) | ||
} | ||
query.in = () => query | ||
selectorQuery.in = function () { | ||
return this | ||
} | ||
return query | ||
return selectorQuery | ||
} | ||
@@ -653,0 +643,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
83
23403
8
741