commit d40b3bbd62be9ba1012d20e64a88c535a6daa69e Author: abearxiong Date: Sun Sep 14 00:21:54 2025 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..23fc1ad --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "xhs-app-test", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.14.0", + "type": "module" +} diff --git a/packages/decrypt-phone-by-data/demo.json b/packages/decrypt-phone-by-data/demo.json new file mode 100644 index 0000000..58b2f27 --- /dev/null +++ b/packages/decrypt-phone-by-data/demo.json @@ -0,0 +1,5 @@ +{ + "encryptedData": "NpiIHuKkhY2S8pCG9WShtDcCLmBhnKkU+m0BLUHJKWkUFrkPay6j3Lc7wkzKat8U/gWsP2WfcMHS6nz48VvjyyKAeXrAxQKEFIxLKslRqntEJnvu5HmANssOypHHk7Y7ovij1QvY+Od/pTBKL73i2AzLoNtXubMTWSPcqG0A/Ov1uy4U7zRZpUIa5otQ+o5dqHc4+rj5EnT2MQ73+QGcFA==", + "errMsg": "getPhoneNumber:ok", + "iv": "aUFhbEhJbWFydjVNQlE4cg==" +} \ No newline at end of file diff --git a/packages/decrypt-phone-by-data/package.json b/packages/decrypt-phone-by-data/package.json new file mode 100644 index 0000000..e860c80 --- /dev/null +++ b/packages/decrypt-phone-by-data/package.json @@ -0,0 +1,14 @@ +{ + "name": "decrypt-phone-by-data", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.14.0", + "type": "module" +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..57970de --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +packages: + - 'packages/*' + - 'xhs-mini-demos' \ No newline at end of file diff --git a/xhs-mini-demos/.xhs-ide/settings.json b/xhs-mini-demos/.xhs-ide/settings.json new file mode 100644 index 0000000..00af293 --- /dev/null +++ b/xhs-mini-demos/.xhs-ide/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.xhsml": "html" + } +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/action-sheet/action-sheet.css b/xhs-mini-demos/api-case/action-sheet/action-sheet.css new file mode 100644 index 0000000..4c2fdfb --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/action-sheet.css @@ -0,0 +1,4 @@ + +.btn-area > *{ + margin: 20px 0; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/action-sheet/action-sheet.js b/xhs-mini-demos/api-case/action-sheet/action-sheet.js new file mode 100644 index 0000000..167bac7 --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/action-sheet.js @@ -0,0 +1,91 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + data: { + alertText: '警示文案', + itemColor: '#ff0000', + itemListLength: 4, + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + handleAlertText(e) { + this.setData({ + alertText: e.detail.value + }); + }, + handleItemColor(e) { + this.setData({ + itemColor: e.detail.value + }); + }, + handleItemListLength(e) { + this.setData({ + itemListLength: e.detail.value + }); + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + onShareAppMessage() { + return { + title: '操作菜单', + path: 'packageAPI/pages/action-sheet/action-sheet' + }; + }, + itemList() { + return Array(this.data.itemListLength - 0).fill('item'); + }, + common(options) { + this.resetApiData(); + xhs.showActionSheet({ + ...options, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + actionSheetTap() { + this.common({ + itemList: this.itemList() + }); + }, + actionSheetTapAlertText() { + this.common({ + alertText: this.data.alertText, + itemList: this.itemList() + }); + }, + actionSheetTapColor() { + this.common({ + itemList: this.itemList(), + itemColor: this.data.itemColor + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/action-sheet/action-sheet.json b/xhs-mini-demos/api-case/action-sheet/action-sheet.json new file mode 100644 index 0000000..d495f15 --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/action-sheet.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "操作菜单", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/action-sheet/action-sheet.xhsml b/xhs-mini-demos/api-case/action-sheet/action-sheet.xhsml new file mode 100644 index 0000000..f3b59cc --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/action-sheet.xhsml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/action-sheet/templates.js b/xhs-mini-demos/api-case/action-sheet/templates.js new file mode 100644 index 0000000..5a71344 --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/templates.js @@ -0,0 +1,65 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: false, + + page_data_4: false, + + page_data_5: false, + + page_data_6: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_3: false, + page_data_4: false, + page_data_5: false, + }); + + xhs.showActionSheet({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_3: true, + page_data_6: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_4: true, + page_data_6: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_5: true, + }); + }, + alertText: this.data.page_data_0, + itemList: this.data.page_data_1, + itemColor: this.data.page_data_2, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/action-sheet/templates.xhsml b/xhs-mini-demos/api-case/action-sheet/templates.xhsml new file mode 100644 index 0000000..72c4e35 --- /dev/null +++ b/xhs-mini-demos/api-case/action-sheet/templates.xhsml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/alipay-auth/alipay-auth.css b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.css new file mode 100644 index 0000000..aa41f34 --- /dev/null +++ b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.css @@ -0,0 +1,3 @@ +.mt-8 { + margin-top: 8px; +} diff --git a/xhs-mini-demos/api-case/alipay-auth/alipay-auth.js b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.js new file mode 100644 index 0000000..3009d8f --- /dev/null +++ b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.js @@ -0,0 +1,44 @@ +Page({ + data: { + authInfo: "", + showLoading: true, + }, + bindInput(e) { + this.setData({ + authInfo: e.detail.value + }); + }, + changeLoading(e) { + this.setData({ + showLoading: e.detail.value + }); + }, + auth() { + if (!xhs.alipayAuth) { + xhs.showModal({ + title: 'xhs.alipayAuth 方法不存在' + }); + } + + const { authInfo, showLoading } = this.data; + console.log("%c Line:19 🍆 authInfo", "color:#ffdd4d", authInfo); + console.log("%c Line:19 🌽 showLoading", "color:#ed9ec7", showLoading); + + xhs.alipayAuth({ + authInfo, + showLoading, + success(res) { + xhs.showModal({ + title: '支付宝授权成功', + content: JSON.stringify(res), + }); + }, + fail(err) { + xhs.showModal({ + title: '支付宝授权失败', + content: JSON.stringify(err), + }); + } + }); + } +}); diff --git a/xhs-mini-demos/api-case/alipay-auth/alipay-auth.json b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.json new file mode 100644 index 0000000..e883ce9 --- /dev/null +++ b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "支付宝信息授权", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/alipay-auth/alipay-auth.xhsml b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.xhsml new file mode 100644 index 0000000..dc38f24 --- /dev/null +++ b/xhs-mini-demos/api-case/alipay-auth/alipay-auth.xhsml @@ -0,0 +1,34 @@ + + + + + 输入的 authInfo 为: {{authInfo}} + + + + + + 修改 showLoading + + + + + + + + diff --git a/xhs-mini-demos/api-case/animation/animation.css b/xhs-mini-demos/api-case/animation/animation.css new file mode 100644 index 0000000..c3c3114 --- /dev/null +++ b/xhs-mini-demos/api-case/animation/animation.css @@ -0,0 +1,38 @@ + +.card-area { + overflow: hidden; + border-radius: 8px 8px; +} + +.animation-element-wrapper { + position: relative; + display: flex; + overflow: hidden; + height: 200px; + margin: 10px 17px; + border-radius: 8px 8px; + background-color: #fff; +} + +.animation-element { + width: 46px; + height: 46px; + margin-top: 54px; + margin-left: 124px; + background-color: #ff2442; +} + +.flexBottom { + position: fixed; + bottom: 0; + width: 100%; +} + +.scroll { + height: 275px; +} +.animation-element2 { + width: 46px; + height: 46px; + background-color: #ff2442; +} diff --git a/xhs-mini-demos/api-case/animation/animation.js b/xhs-mini-demos/api-case/animation/animation.js new file mode 100644 index 0000000..b21dd58 --- /dev/null +++ b/xhs-mini-demos/api-case/animation/animation.js @@ -0,0 +1,126 @@ +Page({ + data: { + isIPhoneX: false, + animation: {}, + animationData: {} + }, + onLoad() { + this.animation = xhs.createAnimation({ + duration: 1000, + timingFunction: 'ease', + delay: 0, + transformOrigin: '50% 50% 0', + }); + + this.animation2 = xhs.createAnimation({ + timingFunction: 'linear', + }); + + this.scroll(); + }, + rotate() { + this.animation.rotate(Math.random() * 720 - 360).step(); + this.setData({ + animation: this.animation.export(), + }); + }, + scale() { + this.animation.scale(Math.random() * 2).step(); + this.setData({ + animation: this.animation.export(), + }); + }, + translate() { + this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step(); + this.setData({ + animation: this.animation.export(), + }); + }, + skew() { + this.animation.skew(Math.random() * 90, Math.random() * 90).step(); + this.setData({ + animation: this.animation.export(), + }); + }, + rotateAndScale() { + this.animation + .rotate(Math.random() * 720 - 360) + .scale(Math.random() * 2) + .step(); + this.setData({ + animation: this.animation.export(), + }); + }, + rotateThenScale() { + this.animation + .rotate(Math.random() * 720 - 360) + .step() + .scale(Math.random() * 2) + .step(); + this.setData({ + animation: this.animation.export(), + }); + }, + all() { + this.animation + .rotate(Math.random() * 720 - 360) + .scale(Math.random() * 2) + .translate(Math.random() * 100 - 50, Math.random() * 100 - 50) + .skew(Math.random() * 90, Math.random() * 90) + .step(); + this.setData({ + animation: this.animation.export(), + }); + }, + allInQueue() { + this.animation + .rotate(Math.random() * 720 - 360) + .step() + .scale(Math.random() * 2) + .step() + .translate(Math.random() * 100 - 50, Math.random() * 100 - 50) + .step() + .skew(Math.random() * 90, Math.random() * 90) + .step(); + this.setData({ + animation: this.animation.export(), + }); + }, + reset() { + this.animation.rotate(0, 0).scale(1).translate(0, 0).skew(0, 0).step({ + duration: 0, + }); + this.setData({ + animation: this.animation.export(), + }); + }, + scroll() { + this.animation.translateX(400).step({ + duration: 0, + }); + + this.setData({ + animationData: this.animation.export(), + }); + + setTimeout(() => { + this.animation.translateX(-700).step({ + duration: 5000, + delay: 1, + }); + + const data = this.animation.export(); + + this.setData({ + 'animationData.commandSetQueue[0].translateX.rule.value': [-700], + 'animationData.commandSetQueue[0].additionalConfiguration': { + duration: 5000, + }, + }); + }, 1000 / 30); + + this.timer = setTimeout(() => { + this.scroll(); + }, 2000); + }, +}); diff --git a/xhs-mini-demos/api-case/animation/animation.json b/xhs-mini-demos/api-case/animation/animation.json new file mode 100644 index 0000000..eb7006b --- /dev/null +++ b/xhs-mini-demos/api-case/animation/animation.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "动画", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/animation/animation.xhsml b/xhs-mini-demos/api-case/animation/animation.xhsml new file mode 100644 index 0000000..2a2af32 --- /dev/null +++ b/xhs-mini-demos/api-case/animation/animation.xhsml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.css b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.css new file mode 100644 index 0000000..ce17160 --- /dev/null +++ b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.css @@ -0,0 +1,5 @@ +._dflex button { + margin: 10px 0; + background-color: red; + color: white; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.js b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.js new file mode 100644 index 0000000..71d3b7a --- /dev/null +++ b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.js @@ -0,0 +1,29 @@ +Page({ + onShareAppMessage() { + return { + title: 'arrayBuffer2base64/base642ArrayBuffer', + path: 'api-case/base64arraybuffer/base64arraybuffer', + }; + }, + + data: { + value: '', + content: [], + }, + + handleInput(e) { + this.setData({ value: e.detail.value }); + }, + + handleArrayBufferToBase64() { + const base64 = xhs.arrayBufferToBase64(this.data.content); + console.log(base64); + this.setData({ content: base64 }); + }, + + handleBase64ToArrayBuffer() { + const arrayBuffer = xhs.base64ToArrayBuffer(this.data.value); + this.setData({ content: arrayBuffer }); + console.log(arrayBuffer); + }, +}); diff --git a/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.json b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.json new file mode 100644 index 0000000..3e8a9e3 --- /dev/null +++ b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "arrayBufferToBase64", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.xhsml b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.xhsml new file mode 100644 index 0000000..1c573d1 --- /dev/null +++ b/xhs-mini-demos/api-case/base64arraybuffer/base64arraybuffer.xhsml @@ -0,0 +1,14 @@ + + + + + 结果:{{content}} + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/caniuse/caniuse.css b/xhs-mini-demos/api-case/caniuse/caniuse.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/caniuse/caniuse.js b/xhs-mini-demos/api-case/caniuse/caniuse.js new file mode 100644 index 0000000..db2bac3 --- /dev/null +++ b/xhs-mini-demos/api-case/caniuse/caniuse.js @@ -0,0 +1,33 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: 'canIUse', + path: 'package/API/pages/caniuse/caniuse' + }; + }, + data: { + value: '', + content: '' + }, + onLoad() { + setTimeout(() => { + this.removeSkeleton(); + }, 500); + }, + bindinput(e) { + this.setData({ + value: e.detail.value + }); + }, + click() { + this.setData({ + content: '初始化' + }); + const ret = xhs.canIUse(this.data.value); + this.setData({ + content: ret + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/caniuse/caniuse.json b/xhs-mini-demos/api-case/caniuse/caniuse.json new file mode 100644 index 0000000..f41fe34 --- /dev/null +++ b/xhs-mini-demos/api-case/caniuse/caniuse.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "检测api能力", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/caniuse/caniuse.xhsml b/xhs-mini-demos/api-case/caniuse/caniuse.xhsml new file mode 100644 index 0000000..e6c0e90 --- /dev/null +++ b/xhs-mini-demos/api-case/caniuse/caniuse.xhsml @@ -0,0 +1,15 @@ + + + + + + 返回值:{{content}} + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/caniuse/templates.js b/xhs-mini-demos/api-case/caniuse/templates.js new file mode 100644 index 0000000..c0a1923 --- /dev/null +++ b/xhs-mini-demos/api-case/caniuse/templates.js @@ -0,0 +1,51 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + let res; + try { + res = xhs.canIUse(this.data.page_data_0) ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/caniuse/templates.xhsml b/xhs-mini-demos/api-case/caniuse/templates.xhsml new file mode 100644 index 0000000..74d6278 --- /dev/null +++ b/xhs-mini-demos/api-case/caniuse/templates.xhsml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/capture-screen/capture-screen.css b/xhs-mini-demos/api-case/capture-screen/capture-screen.css new file mode 100644 index 0000000..ff6fd8a --- /dev/null +++ b/xhs-mini-demos/api-case/capture-screen/capture-screen.css @@ -0,0 +1,25 @@ +.screen_state_txt { + display: inline-block; + font-weight: bold; + font-size: 24rpx; +} + +.screen_state_hidden { + color: red; +} + +.screen_state_none { + color: green; +} + +.recording-resp { + border: 1px solid rgba(0,0,0,.1); + background: #f2f2f2; + font-style: italic; + font-size: 24rpx; + padding: 20rpx; + margin: 16rpx; + color: rgba(0, 0, 0, 0.55); + min-height: 200rpx; + border-radius: 20px; +} diff --git a/xhs-mini-demos/api-case/capture-screen/capture-screen.js b/xhs-mini-demos/api-case/capture-screen/capture-screen.js new file mode 100644 index 0000000..c1e2074 --- /dev/null +++ b/xhs-mini-demos/api-case/capture-screen/capture-screen.js @@ -0,0 +1,109 @@ +const onScreenRecordingStateHandler = function (res) { + console.log('onScreenRecordingStateChanged', res?.state); + if (res?.state && this.data.recordState !== res?.state) { + this.setData({ + recordState: res?.state, + screenRecordingState: res, + }); + } +}; + +function onUserCaptureHandler(res) { + console.log('截屏回调 userCaptureHandler: ', res); + this.setData({ + captureScreenTimes: this.data.captureScreenTimes + 1, + }); +} + +Page({ + data: { + // 截屏 + visualEffect: 'none', + + // 查询录屏的开关状态 + isRecording: 'off', + isRecordingState: null, + + // 录屏状态 + recordState: 'stop', + screenRecordingState: null, + + onScreenRecordingStateChanged: false, + onUserCaptureScreen: false, + captureScreenTimes: 0, + }, + onLoad() { + // 监听用户截屏事件 + const userCaptureHandler = this.userCaptureHandler = onUserCaptureHandler.bind(this); + xhs.onUserCaptureScreen(userCaptureHandler); + + // 监听用户录屏事件 + const screenRecordingStateHandler = this.screenRecordingStateHandler = onScreenRecordingStateHandler.bind(this); + xhs.onScreenRecordingStateChanged(screenRecordingStateHandler); + + xhs.showToast({ title: '正在监听用户截屏事件、录屏事件!!' }); + }, + handleSetVisualEffectOnCapture() { + const _this = this; + this.setData({ + visualEffect: this.data.visualEffect === 'none' ? 'hidden' : 'none', + }); + xhs.setVisualEffectOnCapture({ + visualEffect: _this.data.visualEffect, + success(res) { + console.log('setVisualEffectOnCapture success', res); + }, + fail(err) { + console.log('setVisualEffectOnCapture fail', err.errMsg); + }, + }); + }, + handleGetScreenRecordingState() { + const _this = this; + xhs.getScreenRecordingState({ + success(res) { + console.log('getScreenRecordingState success', res?.state); + if (res?.state === 'on') { + _this.setData({ + isRecording: 'on', + isRecordingState: res + }); + } else { + _this.setData({ + isRecording: 'off', + isRecordingState: res + }); + } + }, + fail(err) { + console.log('getScreenRecordingState fail', err.errMsg); + }, + }); + }, + // 取消「截屏」监听 + handleOffCaptureScreen() { + if (this.userCaptureHandler) { + xhs.offUserCaptureScreen(this.userCaptureHandler); + this.userCaptureHandler = null; + } else { + this.userCaptureHandler = onUserCaptureHandler; + } + + xhs.showToast({ + title: '取消截屏监听, 接下来将无法监听到截屏事件,截屏次数不会更新!', + }); + }, + // 取消「录屏」监听 + handleOffScreenRecordingState() { + if (this.screenRecordingStateHandler) { + xhs.offScreenRecordingStateChanged(this.screenRecordingStateHandler); + this.screenRecordingStateHandler = null; + xhs.showToast({ + title: '取消录屏监听, 接下来将无法观测到录屏消息!', + }); + this.setData({ + screenRecordingState: null + }); + } + }, +}); diff --git a/xhs-mini-demos/api-case/capture-screen/capture-screen.json b/xhs-mini-demos/api-case/capture-screen/capture-screen.json new file mode 100644 index 0000000..8e68437 --- /dev/null +++ b/xhs-mini-demos/api-case/capture-screen/capture-screen.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "截屏录屏 API", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/capture-screen/capture-screen.xhsml b/xhs-mini-demos/api-case/capture-screen/capture-screen.xhsml new file mode 100644 index 0000000..04d2775 --- /dev/null +++ b/xhs-mini-demos/api-case/capture-screen/capture-screen.xhsml @@ -0,0 +1,46 @@ + + + + 当前设置: {{visualEffect}} + 【当前录制的屏幕内容将被隐藏】 + 【当前录制屏幕不受限制】 + + + + + + 当前截屏次数: {{captureScreenTimes}} + + + + + + 当前录屏状态: {{isRecording}} + + + + {{ isRecordingState ? JSON.stringify(isRecordingState, null, 2) : '暂无返回' }} + + + + + 当前录屏状态: {{recordState}} + + + + {{ screenRecordingState ? JSON.stringify(screenRecordingState, null, 2) : '暂无信息' }} + + + diff --git a/xhs-mini-demos/api-case/check-session/check-session.css b/xhs-mini-demos/api-case/check-session/check-session.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/check-session/check-session.js b/xhs-mini-demos/api-case/check-session/check-session.js new file mode 100644 index 0000000..530afff --- /dev/null +++ b/xhs-mini-demos/api-case/check-session/check-session.js @@ -0,0 +1,29 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '检查登录状态是否过期', + path: 'package/API/pages/check-session/check-session' + }; + }, + data: { + isAccess: '' + }, + checkSession() { + xhs.checkSession({ + success: msg => { + console.log(msg); + this.setData({ + isAccess: '已登陆' + }); + }, + fail: msg => { + this.setData({ + show: true, + isAccess: '未登陆或登陆失效' + }); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/check-session/check-session.json b/xhs-mini-demos/api-case/check-session/check-session.json new file mode 100644 index 0000000..3609ef3 --- /dev/null +++ b/xhs-mini-demos/api-case/check-session/check-session.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "检查小红书登录状态", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/check-session/check-session.xhsml b/xhs-mini-demos/api-case/check-session/check-session.xhsml new file mode 100644 index 0000000..de98b36 --- /dev/null +++ b/xhs-mini-demos/api-case/check-session/check-session.xhsml @@ -0,0 +1,11 @@ + + + + + 当前登陆状态:{{isAccess}} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/check-session/templates.js b/xhs-mini-demos/api-case/check-session/templates.js new file mode 100644 index 0000000..0c4937a --- /dev/null +++ b/xhs-mini-demos/api-case/check-session/templates.js @@ -0,0 +1,44 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.checkSession({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/check-session/templates.xhsml b/xhs-mini-demos/api-case/check-session/templates.xhsml new file mode 100644 index 0000000..15c5b96 --- /dev/null +++ b/xhs-mini-demos/api-case/check-session/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/choose-address/choose-address.css b/xhs-mini-demos/api-case/choose-address/choose-address.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/choose-address/choose-address.js b/xhs-mini-demos/api-case/choose-address/choose-address.js new file mode 100644 index 0000000..23da5f1 --- /dev/null +++ b/xhs-mini-demos/api-case/choose-address/choose-address.js @@ -0,0 +1,26 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '收货地址', + path: 'packageAPI/pages/choose-address/choose-address' + }; + }, + data: { + addressInfo: null + }, + chooseAddress() { + xhs.chooseAddress({ + success: res => { + console.log('res:', res); + this.setData({ + addressInfo: res + }); + }, + fail(err) { + console.log('err:', err); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/choose-address/choose-address.json b/xhs-mini-demos/api-case/choose-address/choose-address.json new file mode 100644 index 0000000..d4349d2 --- /dev/null +++ b/xhs-mini-demos/api-case/choose-address/choose-address.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "收货地址", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/choose-address/choose-address.xhsml b/xhs-mini-demos/api-case/choose-address/choose-address.xhsml new file mode 100644 index 0000000..8f65216 --- /dev/null +++ b/xhs-mini-demos/api-case/choose-address/choose-address.xhsml @@ -0,0 +1,38 @@ + + + + + + 收货人姓名: {{ addressInfo.userName }} + + + + + + 地区: {{ addressInfo.provinceName }} + {{ addressInfo.cityName }} + {{ addressInfo.countyName }} + + + + + 收货地址: {{ addressInfo.detailInfo }} + + + + + + 手机号码: {{ addressInfo.telNumber }} + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/choose-address/templates.js b/xhs-mini-demos/api-case/choose-address/templates.js new file mode 100644 index 0000000..377d7ed --- /dev/null +++ b/xhs-mini-demos/api-case/choose-address/templates.js @@ -0,0 +1,44 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.chooseAddress({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/choose-address/templates.xhsml b/xhs-mini-demos/api-case/choose-address/templates.xhsml new file mode 100644 index 0000000..af8be35 --- /dev/null +++ b/xhs-mini-demos/api-case/choose-address/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/clipboard-data/clipboard-data.css b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.css new file mode 100644 index 0000000..49ce329 --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.css @@ -0,0 +1,6 @@ + +._dflex button { + margin: 10px 0; + background-color: red; + color: white; +} diff --git a/xhs-mini-demos/api-case/clipboard-data/clipboard-data.js b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.js new file mode 100644 index 0000000..495060e --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.js @@ -0,0 +1,36 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '剪切板', + path: 'packageAPI/pages/clipboard-data/clipboard-data' + }; + }, + data: { + value: 'edit and copy me', + pasted: '' + }, + valueChanged(e) { + this.setData({ + value: e.detail.value + }); + }, + copy() { + xhs.setClipboardData({ + data: this.data.value, + success: res => {}, + fail: res => {} + }); + }, + paste() { + xhs.getClipboardData({ + success: res => { + this.setData({ + pasted: res.data + }); + }, + fail: res => {} + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/clipboard-data/clipboard-data.json b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.json new file mode 100644 index 0000000..3ac4a23 --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "剪切板", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/clipboard-data/clipboard-data.xhsml b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.xhsml new file mode 100644 index 0000000..98e1e09 --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/clipboard-data.xhsml @@ -0,0 +1,19 @@ + + + + + + + {{pasted}} + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/clipboard-data/templates.js b/xhs-mini-demos/api-case/clipboard-data/templates.js new file mode 100644 index 0000000..53c4eaf --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/templates.js @@ -0,0 +1,90 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + + page_data_5: false, + + page_data_6: false, + + page_data_7: false, + + page_data_8: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.setClipboardData({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + data: this.data.page_data_0, + }); + }, + + page_fun_2() { + this.setData({ + page_data_5: false, + page_data_6: false, + page_data_7: false, + }); + + xhs.getClipboardData({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_5: true, + page_data_8: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_6: true, + page_data_8: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_7: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/clipboard-data/templates.xhsml b/xhs-mini-demos/api-case/clipboard-data/templates.xhsml new file mode 100644 index 0000000..7fdf717 --- /dev/null +++ b/xhs-mini-demos/api-case/clipboard-data/templates.xhsml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/download-file/download-file.css b/xhs-mini-demos/api-case/download-file/download-file.css new file mode 100644 index 0000000..da8053c --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/download-file.css @@ -0,0 +1,7 @@ + + +._dflex button { + margin: 10px 0; + background-color: red; + color: white; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/download-file/download-file.js b/xhs-mini-demos/api-case/download-file/download-file.js new file mode 100644 index 0000000..a33f21f --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/download-file.js @@ -0,0 +1,77 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + data: { + remoteFilePath: 'https://fe-video-qc.xhscdn.com/fe-platform/541cb4b0e802f5bdd91845e85082132453f8d4f5.pdf', + filePath: '', + fileType: '' + }, + onDownload() { + this.task = xhs.downloadFile({ + url: this.data.remoteFilePath, + // 文件 ID + success: res => { + console.log('【downloadFile success】:', res); + this.setData({ + filePath: res.tempFilePath || res.filePath + }); + }, + fail: res => { + console.log('【downloadFile fail】:', res); + } + }); + if (this.task) { + this.task.onHeadersReceived(res => { + console.log('【onHeadersReceived】:', res); + }); + this.task.onProgressUpdate(res => { + console.log('【onProgressUpdate】:', res); + }); + } + }, + onAbort() { + this.task?.abort(); + }, + offHeadersReceived() { + this.task?.offHeadersReceived?.(() => { + console.log('【offHeadersReceived】'); + }); + }, + offProgressUpdate() { + this.task?.offProgressUpdate?.(() => { + console.log('【offProgressUpdate】'); + }); + }, + removeSavedFile() { + xhs.removeSavedFile({ + filePath: this.data.filePath, + success: res => { + console.log('【removeSavedFile success】', res); + }, + fail: res => { + console.log('【removeSavedFile fail】', res); + } + }); + }, + openDocument() { + xhs.openDocument({ + filePath: this.data.filePath, + fileType: this.data.fileType || undefined + }); + }, + handleRemoteFilePath(e) { + this.setData({ + remoteFilePath: e.detail.value + }); + }, + handleFilePath(e) { + this.setData({ + filePath: e.detail.value + }); + }, + handleFileType(e) { + this.setData({ + fileType: e.detail.value + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/download-file/download-file.json b/xhs-mini-demos/api-case/download-file/download-file.json new file mode 100644 index 0000000..f32a42b --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/download-file.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "下载文件", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/download-file/download-file.xhsml b/xhs-mini-demos/api-case/download-file/download-file.xhsml new file mode 100644 index 0000000..588bd71 --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/download-file.xhsml @@ -0,0 +1,36 @@ + + + + + + 远程文件路径 + + + + + + 本地文件路径 + + + + + + 文件类型 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/download-file/templates.js b/xhs-mini-demos/api-case/download-file/templates.js new file mode 100644 index 0000000..4f0bd48 --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/templates.js @@ -0,0 +1,171 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + + page_data_8: "", + + page_data_9: "", + + page_data_10: false, + + page_data_11: false, + + page_data_12: false, + + page_data_13: "", + + page_data_14: "", + + page_data_15: false, + + page_data_16: false, + + page_data_17: false, + + page_data_18: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_4(e) { + this.setData("page_data_3", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + xhs.downloadFile({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, + url: this.data.page_data_0, + header: this.data.page_data_1, + timeout: this.data.page_data_2, + filePath: this.data.page_data_3, + }); + }, + + page_fun_6(e) { + this.setData("page_data_8", e.detail.value); + }, + + page_fun_7(e) { + this.setData("page_data_9", e.detail.value); + }, + + page_fun_5() { + this.setData({ + page_data_10: false, + page_data_11: false, + page_data_12: false, + }); + + xhs.openDocument({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_10: true, + page_data_13: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_11: true, + page_data_13: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_12: true, + }); + }, + filePath: this.data.page_data_8, + fileType: this.data.page_data_9, + }); + }, + + page_fun_9(e) { + this.setData("page_data_14", e.detail.value); + }, + + page_fun_8() { + this.setData({ + page_data_15: false, + page_data_16: false, + page_data_17: false, + }); + + xhs.removeSavedFile({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_15: true, + page_data_18: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_16: true, + page_data_18: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_17: true, + }); + }, + filePath: this.data.page_data_14, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/download-file/templates.xhsml b/xhs-mini-demos/api-case/download-file/templates.xhsml new file mode 100644 index 0000000..a49067a --- /dev/null +++ b/xhs-mini-demos/api-case/download-file/templates.xhsml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/editor/assets/iconfont.css b/xhs-mini-demos/api-case/editor/assets/iconfont.css new file mode 100644 index 0000000..9ff2f5c --- /dev/null +++ b/xhs-mini-demos/api-case/editor/assets/iconfont.css @@ -0,0 +1,240 @@ +@font-face {font-family: "iconfont"; + src: url('//at.alicdn.com/t/font_945958_zfsfjju1dim.eot?t=1547618146468'); /* IE9 */ + src: url('//at.alicdn.com/t/font_945958_zfsfjju1dim.eot?t=1547618146468#iefix') format('embedded-opentype'), /* IE6-IE8 */ + url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAABdkAAsAAAAALvAAABcWAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCKSgrBdLN+ATYCJAOBZAt0AAQgBYRtB4YRG7smRSQnqz4jqjWV7P9bAidjcG3cMssRirV6WRdYIhSPI7KwpqTEWqtc6K4YeK6yr9OvxbcdprxM/yib6gio0BZ+n7Rt/V9XwX9lINMYSgkPeG++5I+ba4GUClKqlqSIS6hYyq38QNv8d5x65OEhRh+sdQE7jL5NnPgnihL75TgDFuUqOW2WuvRY8VkVv8LJj8Zl6Y80f+Xx8HZ7/9/tWGoR13aUWBZEaSABZpQkkIVz9psLXwo4ADJiSk74UeimQCl/LdkLu3A5Lb9fLdiAfKs0jVd6s5bW0vrllU9aXUOpAIbgIBQAP4AF4GQAwNjv66z+twPSe3YyEXkJoUQ7zmyGcJHc2NVJ3y0N0HJgEQJLfBSQrqKmOVa8TZaSWNiEpAWmBqH+vylGDwgxZs4BANAGCCDwC//E1Xjv8RV9Igu2Cl/+HldFYWn3eMChdGNoISXOzb/OdLV8cYCdC0/AGw1beE226f8vwwcrF1k++JYDtkM61rHsAPEEG2Or7ysYCtZdilMAh63AY6e+jmP3qVBzmePWPyDU3kl9GHOfD1sDjzw0JUUixbX+Wp8hgFtelxinUgsImeg1AURf5lWDUKiZim3BSbAlb2vGLpQztwwCn/z74mMcDpJV0LsvzqI6oL+d0InD/qznq9VobgRW78AAXWBCntKlOKD+qsvgPvzOkJgBa0Wm9DtBKi1KPiNGnaXW2aLZ9/6ZPFXz5zLruHXfxERF2tTejuTtxONJF9iLS6Lns9rShlznoJfC2gm2xX10zPS5AVb8KQ8QMjwkL7egkJi0FB+/AJMlLCIqwebg5LJkiEvKyskrKCopq6iqqWtoamnr6OrpGxgaGZuYmplbQDTY9ALkba+XUBMYEFCpIAOlBR4oCkiofOCFMgI3lB0EoRgQgqoDMaglIA21FKSg1gEf1Bbgh2oGAajvgQn1H7BwnQzCuD4PIrhWgSiuf4IEbgywcasFDtzqgBM3B3DhXgeWeE4EBrQIxKEjQBJ6A8hCbwQ56E0gD+0CBWgWFKEbQAm6EZShm0AFuhlUoVtADboV1KHbTANqh2lCbpgWtBWmDW2D6UDbYbrQDpgetBOmD+2CGUAdMEOoE2YE7YYZQ3tgJtBemCl0BGYGeWHm0AmcsACwcl98APALuAfgvdCFePA6xwmWI0lmMIBucnImpQhjJZc8FHMoMUwEpuUSkFKxqXUhZwocJppG7g5lRWlxWeEco+wVN5zisZtVpL9w3/MmkyqHMS3ctynbem5lnk1RccrFpipqksYNMD3MamvcVFj6yWTix1lVdexd2SCkpCOw9pOuQSseVli8owDLTKAdNaS0se2Cp4NS1JQNF06dCWlCOUyC517Nm779nP/w50B+3UrlHq6eFtLRSX57SeoR2WIO5Q3XjCr2eaJbUCO66DgMmTb1BOYkuKlu70buw8ticceQVNc05DQpEuCABw184AcabEQOefRE/hwHIkVepip6kMQZQQo0ebgBAbKfymd6MNotLFMpQYZHhQkUCT7+2fi2InSE4aJe2sP8eAIUiBcdyC27w8VnqyVINaBDhRXwIDeOpOsHs353eqJMqTQx25TYU1RV/vp9Sod+qgNqOMwihEuRkCMSZsoc4vRco56qrzkzhvZnUSwDW1nY70k000Tr+VWu/DFz5vb/oZbf6NktJWx6SaXqra+UeKcpl6s733LySCl+JafnzaJROM8E4dFPE7zDP69EAixFSJj2ZQAoPvxxvGfgh0YmBDx6GkNmdmyHEYlYERlUaqS/Pko8V+ofO1Roslatoyp2g+E4MeoOpETSjpgokoDs9I/vVtUCLfAdPIM/Lg8+/nmid+inc3GQoRHrOxK4/yBer1J4RsDkC5iOkUTP3bfFscn+tv7iTPFqXs9NE64VjsYzLKfPVuRUsVxV0vV4Z3PiatYosFkHE8rbaM6stInu4+vXs2OTSbSjtTfLi3vL83ujdjnaSwirACuBMVaVXCm64lKjsmRJy0BJ7314dfp0m+iRxGdzBR6cZCBcG+P0X8eQOdruuQKlaiJeTY/qmVZzLTO2Hw+3Pi0so+Riq3g1raemAVnCO3NGLDh0LWNk8biRYZFN1B2TImSLE9ejVOnv1Sp1j5qepYSGFlA+83AiQJVEG+CGHsqQSIDlOkvjDovI1NLTprSVuGOylG62X46houlKqqjYNqLrxhr6ZgCzInWW3YkKHK9hqQix+/UciTqZaWwKCewnY25XWn5iPxCoWh3/F9HvzJLF0e7A/JFw+g8A7CdKkSAFyiCJGj9r05XHYChtdBxY0xduMvp0Oxp0Xeo3nCOVqu4vmvnRazMRTgf8SK5EjMtEsUne4DBLj67vIMM1HKYIcsKiDQeWNwvWcmtAj3mjovv9tY4MCFdyozy9+enB68WxvHEECXQLVFSAGhkI9I4JvEj0tKHMWUqx/WzAihA7ihXSPBBIIqwXvMcnMzvdwKPpPnuJI7JlI3LArKhi5605B2eTrzcILtSMeAMzVvC8ysh0wZRAR6RkrcX7NHwbtbGmvJJPCgn9fYVz/pBPE0qQh6MxEt02XYrqsblLQs032qCi+HA1wW5hn9s3LmBruJSVrhHb2wUs3j1sT5fxqLj7JHfU/vsNqkeFJ77BD1d3ii8OBYmVYhlK+zIzhCupUVxvq3U2lhpZMx0lI6WWl/QcWTOqdLpmWo+0WWcDL3/cM5h/0kvF8kLdC3kPr07UQLPRlXlaCKq1NiEKjZ5mZOTADd4oukwbvF2FjkuvH/y6XHz8/cTGLjUfEYnQbV1RGtdiDcG6M+Nb3cXtBiGrFm+T1bNxcAaSKN1hnAuRmiQTaEI1XKpse1AidbJsA5YjXG++jJ18PzHZP3Tr2SneGHSLczJhpSDAt1Iqvbzy+svxumxVNHNaq0iW96hVKmV4TorVaqWrpHjFqrpXLkEp02qR3NO2VzPGEWH/0bIZ4UL7ofeZulOWO+IL+etqvKGDwc8+MitrUOyt1ieNJadcDaAW4dj6SZET+CQmRL62ESmQjaNMPF2l8Boos1MpNBawRRMdD7a1q3G1VVY80qlNGVjjWEXnxoj8dlnWUYGyZj/UdNfL015l+rg49vYUoxIXfKK57+didGA53dRn3QBovyEDxTJ1raZ/3aH304JUpAEicsiBdg5VUcELiSTWNstiQ65ERAruxu8XNSrAZGUYzTTRc1oN4+BD/gHV35on54GrJiwf9ABac8CwO6hpQhDBuhHlFhMAjcgT59ULkNuylmRtG3j4fNovPZEqzS9P9XZFLvUPMNetDsUebGmPFJllMkY2i29cZ2uC0lLtvbSXl5bqEczDz5k2dzKfsq7EOpzhx9H2k53uG4rW1vFaktLeZg0+lDrbX+7zxg6q7tPRnp4nsTiwDOVffcwWyxhStloEnZPSUb5M9JJiPRqSfrZR2ev0Z81oN7coaQ51Yi8LmhJ44YRjj1uEHNFzR60biwfllwn0dskl54ybpKIHnplLMAZe8ZmD0JAWYA/GN373p4tm+T+vuqvpeuXPJp785TqAwIf+H8v/HBxzfdj148Ki48f08rNYifCMXH/9OGp5/BLhWewRdlbIB99aim3KNhH7CM+Ez9wirkdUGIW6ZnhgKME84RnRoss9qg/nplf0mIsVuFjanUyE/Rfa4V+WBdctK5wDq9UV3LbajizMq12Ya41sIf7vYW/ftt2aZE1JtaXetqR0LT6QVDxvuW29fc5qADuDFCMGu92AWDU8mmr1ag0Y5JrQGc+h/AOhc+rYuXPnVMqQqxXz7bODjJ9X9Z0WjGhOaUYEp/v7h+UZ5PUjsF5ksqvNFBKpwcjXSEzTYn52SVi+4ch1MkM+3Pi65YmUT/LSJ9uJeUTSt61PMrK37bOMHcDK8fIJA06iC2LwaB7LwPhEjOm+ZCaJlnSEPES/D7n1Pu4m5NaJkJCTAZYByLJf+UXv9rDbezs7b+/ZjgEK+rZ7t5s7S8skktLyjo4JuaUs606/h/bk4zsADWxW52fXgrK7suC1ivSK6OHoRbAo7El04JOYMC8dgPR1kXujn4TFJYNCYZjTfD27+iio9LOFQlWptIXrfagfLtzpr9JXZWXsaghFqiqVhdOaCivLdRfT+ZaHxT7xSPSIxCcZfr5FPShLj9eZ/MNhf8zHQtqYmcf7efw4zv+TRt5fFGmn/oyR875YsLRw7F9VMZefj4GXC4JeKp3ygtvxzbDJE/IDz3aWjebha0fElJeNg0Rw+SebTaXVaxU2ShSeW7WFyP8EeI9mECN4SYlJ23ErVPq+7fhn1upW+9HDJcURq4jJlUFHk2YznGk9ZQxvHCeRj+0Qjks9gkXFRDwbsbxCZdFGhYrUzznXI3At63DcT7FFFdXiqFCxqlmiDtEL7sLBq7NvJAbW5Tg34yGq9Tm2zeFOcLqyTG6mqrbtWjGzyLyBVH8zq1cBCe051v2fyJfBMo1Fbda88/3UcRZ/W45t/+vyT4A0qy0Kapy8MNnz7hk5lUzJz7zrIalENyxcfVB1MGvADQefzWdUrnPTtQVzrTPWtSUVRy82rx9lEQan+Li/fpnSQpUHwwz+tuzl2v5PIywqOqRchoVrPCpPpoE7kSIPBk7n5+B04GByYSIE36oQDU7MvyjUX/zW8jtXeC9mDRiqye2iHybeM2RdnPS/wvLBS9H+NVKQ5khAys8jyZHC08gGYAwxy3mlr614X5cYY4VihimGuXjTY8/P630E827ZGGIM880/YgX0n/sYAtJ2f2HVhnFMY9u7lnfbGhkuTGsVcsJcjKt/qZ7DcoUcneTCurBpb9BvTOMW15LA+KGdMYWJXuxr7DkVBt8tKQG9nJPrey24xWrT42dxawrGyT3YJMwj57Cm4yUGa7QHLwr2sRYZW1ImMZxcnYS56tZjqRcqknugjeIZc48Ysm7EI4g67omXEvePUNLPHT2J2/VdoD7QsyzQEdi1y+THCRxYnd/Ub+oIsnSUIQi09ZFMGBvGZNZI+rTmeZwJEyL5vOY0LesOGyYiZzTPCMmIqNtitdZuGZMREh4wpjYO9T2dpsRbZYoEhWzhcpkqQbXnmC2BwJcvlCni1bKtuOp8yS0fAVEC70xWd7t9beHyGHgDY+Oq5eVkuQlZfj9fQb1sJ80OtMeMr9iQFSsRm4OytyG6byWPo4YkRs4oVjGPxUZWPBQ17HbqaMRmAxponiuN6GbzD78WHVGucTjXKtc6HGsjhyPXcg+9Q1FDoCUVDucaJa9cyz3quNE7HnFJUOOIysJ8Sp9EDYO1L0/w4uA37Bug6fBvk+kZMHDtcVKSlIgnZEloFzlgCoZ8GxqM+iYqGPoXLnlNf4XTtPWIjPP5uLjpsV3bt9vtXCwVy61e0wVXe8jwIMIgwXBiIi5i7RjJFAb6sqtkZ8lR2Uca2nh6L7uHyo4eozuOBHLk1wLXiACyBaMBE07gLNNMAQ0btfEtXZnJZyrTHVQdcWKcRmvojl/i5TKfTB5f+vKmx3Wa7M6wnnMHJ3yhbw2ahj885z8/Of7ty9L5sxv3I7qAvnGt5zy7plCmq9lHG4fkSxMQzqEf0ASRYoYu0Wyz3EktpHJEJZWta+LXJLRIrQk7xm2uK2lOP3ezcQRvQVHjNiNC/P+CoXkKjcPOUvncFWDMEUaa/JAZby6LI3SKRZD55Vlzzc+xzrK6iim1FaVZLynyDNmzFS8Z8hfZEkPwe+YC6XrVSv/02dLSfENW1dJnEmleY479ucxpSffy5lumprNTbImTIRORiVadm/9qe2mVXqb795+LX//2GT0mAnsfLabSHWvgOASgoIdm61PXxzLsNVbp2pV81PynrjVg52nGKXcVeHFwnbTSql0xS6Nsul8QauwZnz6XMVZdQBc8m8FmuB3WlihSMlIUJZz9KduXXuQmWfbiV6QelUzxkcUFN4ci5gIOyk4yBUiU7g75918zcTcQwaCD56scH3rvHgr2CSJoV9b8U/rKy3G7xl6PYL3Pt15YMADvETTEDAEdLkj+7oNNYF+9chVUxi6pGhoAZ/7HO9+fAcOjDP9F72t0X85Ero5cnQl5+mrIuL4VZNMwHIDJaP0srX6UrPfXk/9s6yHiZYw4hm3KOT++TbuR2IO98NOySsGzXKHb1Ufeb30h+1ktaTq6q+Oie3z6LDpvVaxzLt6iCtcTUSKYipJsgGWsSG/AyzDAW5oFly4Jmrl6DrHU11sSIwMAw0sEzX+HfW2cEUkNmkKSJPNNz7PETdbgc7/tmZNYlLYjzokoqZRnlREpzpmnttbaj+zwTVp/Mb3Ilqd668uQ21+FXIJy75W/IKbxQvlTxd1fBYq4oO6+Prr/xugF5AI/F9myBZkrUPASDFKPPCauydSya8SHi0eFXJQkd/X9+m1XHL02tfnaHH3rbK1K3yP7pRNcnDrOHTuhnT1QOeZhbfxADg7j3RQVV9VF6WyKrtjpcRwl0PXunvi5Tkfpus6OOEDjgscGNGgNqhm4fuooTuBCFs9f2BVr6B0PkWWTJ8aXdHf7MnrHj7XrslIcy14KZjZ2e3L3n8jes8AtUsW5CwoLz/TMOg+ZbBIgArXDocc5XG8wHA7ZL8bhJJQoKlASjnmFMk6qN5QcRpZ21+lAkAgUQd56wHQJKaKXErpxt7DdzUH1EpSwC+8S6jEOczKsfyXA9QdPq9igxwRQ7rou4HkQgqAZAJYbZBUFO4naBHfIbNlm/BZ0FK0noi8FCwD4bu+hMzGWR98VBPRPPTJVF/AQNUEqu9QV99HpMBosRl2oucaPamRen6Bf97uWtsaF6lBj1WQbQl8ouGXS60VpUPq7KCOGTjVlFNqP+KO3vF9UC/5t99AJMn/TYl7BKPeLbE2VST92T5HptwRek8BRETWDVCimEzuCktDQahWlxQT/GZaY+B+RaCou/EYDqkDJ8NI3fVGVAPSvBJdQ6hD87g0IrtT5uNG5f9lnBs37IpVdnvubED0io6v/9OYcPz7uc4dfgJP8IyjE3/F87j+p3KFjAJHV9n4G1btRcWtkf7rqvwZyg8ev/OIyJHA7h8Bf/cvD/naLEtNGLnEKvtVEySE30eBUlUxPd6LFYzrR5nSY6Nbx7vM9IoJDovoM2n5aE4Wg3xMlvy9iyDx/iAnPy0RL3D9sMyBjottrkyI96r23XwUEQZ3l24yU5yIqpO21fY8mOQgksPikzxgiec4uzy7O9e+QMZjIEVfmSqTIiuCr7K2VBZ3zWR18iUrOLHX10/l5sfkOZ8pXe20XAQICaZnc1p2ZKB4rzizakb/+PWQkDgiKLR5m/gwFEd185tKZCw3pHWOtLVbFGq0YV4TwQsbWD7xK5i3hyDk1XqaWd1ZCijhjUxi1J+dkT4UuOyteqeYlY/RtlRZeJUUJRIsRK078bw6UPwv+xKSUSkhYRFRMXEJSSlpGVk5eQVFJWUVVTV1DU0tbR1dP38DQyNjE1MzcwtLKuqMVtT9KrP0JsUaWhk/CabMH/1WRdjgofKhATi2CxnB6Kc7qZla3Xb1rvDmEkOpGHXBFuD7SINgxnJYb5Z0PvcQI6jT0SOp4dn91nRNwSUta6ARsfSrT/P5vrM0kdBlqntqCG1lks6Vi93QlOr5u97aonh1FOcnBq8QdR4wqExkrzaW5f7AmNj1NAZWQ59MgTpjaSWhFdE8Bzh0XaWepES2wsqlbKXHE5wTUKpANbiJqQ1/wLpp3lYWQnFrDTohLqtfi9jptUg3kCLtlZoZno1PtjMaWeGvjTgYTSTOQE0StHQlpoAqaOVCfpXzbpCRQaWD7KwT3FdwTiSlf2LcJ8qJC/TVUrrYJNqlXbggl6/ttgSM2d8kX1mqbHHAnBUpPOkmB6pCGS0w1xScmAefUjxbZ1IAvot2ro1f15aBkAFI/1KCIzd4e') format('woff2'), + url('//at.alicdn.com/t/font_945958_zfsfjju1dim.woff?t=1547618146468') format('woff'), + url('//at.alicdn.com/t/font_945958_zfsfjju1dim.ttf?t=1547618146468') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */ + url('//at.alicdn.com/t/font_945958_zfsfjju1dim.svg?t=1547618146468#iconfont') format('svg'); /* iOS 4.1- */ +} + +.iconfont { + font-family: "iconfont" !important; + font-size: 16px; + font-style: normal; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.icon-redo:before { + content: "\e627"; +} + +.icon-undo:before { + content: "\e633"; +} + +.icon-indent:before { + content: "\eb28"; +} + +.icon-outdent:before { + content: "\e6e8"; +} + +.icon-fontsize:before { + content: "\e6fd"; +} + +.icon-format-header-1:before { + content: "\e860"; +} + +.icon-format-header-4:before { + content: "\e863"; +} + +.icon-format-header-5:before { + content: "\e864"; +} + +.icon-format-header-6:before { + content: "\e865"; +} + +.icon-clearup:before { + content: "\e64d"; +} + +.icon-preview:before { + content: "\e631"; +} + +.icon-date:before { + content: "\e63e"; +} + +.icon-fontbgcolor:before { + content: "\e678"; +} + +.icon-clearedformat:before { + content: "\e67e"; +} + +.icon-font:before { + content: "\e684"; +} + +.icon-723bianjiqi_duanhouju:before { + content: "\e65f"; +} + +.icon-722bianjiqi_duanqianju:before { + content: "\e660"; +} + +.icon-text_color:before { + content: "\e72c"; +} + +.icon-format-header-2:before { + content: "\e75c"; +} + +.icon-format-header-3:before { + content: "\e75d"; +} + +.icon--checklist:before { + content: "\e664"; +} + +.icon-baocun:before { + content: "\ec09"; +} + +.icon-line-height:before { + content: "\e7f8"; +} + +.icon-quanping:before { + content: "\ec13"; +} + +.icon-direction-rtl:before { + content: "\e66e"; +} + +.icon-direction-ltr:before { + content: "\e66d"; +} + +.icon-selectall:before { + content: "\e62b"; +} + +.icon-fuzhi:before { + content: "\ec7a"; +} + +.icon-shanchu:before { + content: "\ec7b"; +} + +.icon-bianjisekuai:before { + content: "\ec7c"; +} + +.icon-fengexian:before { + content: "\ec7f"; +} + +.icon-dianzan:before { + content: "\ec80"; +} + +.icon-charulianjie:before { + content: "\ec81"; +} + +.icon-charutupian:before { + content: "\ec82"; +} + +.icon-wuxupailie:before { + content: "\ec83"; +} + +.icon-juzhongduiqi:before { + content: "\ec84"; +} + +.icon-yinyong:before { + content: "\ec85"; +} + +.icon-youxupailie:before { + content: "\ec86"; +} + +.icon-youduiqi:before { + content: "\ec87"; +} + +.icon-zitidaima:before { + content: "\ec88"; +} + +.icon-xiaolian:before { + content: "\ec89"; +} + +.icon-zitijiacu:before { + content: "\ec8a"; +} + +.icon-zitishanchuxian:before { + content: "\ec8b"; +} + +.icon-zitishangbiao:before { + content: "\ec8c"; +} + +.icon-zitibiaoti:before { + content: "\ec8d"; +} + +.icon-zitixiahuaxian:before { + content: "\ec8e"; +} + +.icon-zitixieti:before { + content: "\ec8f"; +} + +.icon-zitiyanse:before { + content: "\ec90"; +} + +.icon-zuoduiqi:before { + content: "\ec91"; +} + +.icon-zitiyulan:before { + content: "\ec92"; +} + +.icon-zitixiabiao:before { + content: "\ec93"; +} + +.icon-zuoyouduiqi:before { + content: "\ec94"; +} + +.icon-duigoux:before { + content: "\ec9e"; +} + +.icon-guanbi:before { + content: "\eca0"; +} + +.icon-shengyin_shiti:before { + content: "\eca5"; +} + +.icon-Character-Spacing:before { + content: "\e964"; +} diff --git a/xhs-mini-demos/api-case/editor/editor.css b/xhs-mini-demos/api-case/editor/editor.css new file mode 100644 index 0000000..492a8f0 --- /dev/null +++ b/xhs-mini-demos/api-case/editor/editor.css @@ -0,0 +1,51 @@ +@import './assets/iconfont.css'; + +page > view { + max-width: 100%; +} + +.container { + position: absolute; + top: 0; + left: 0; + width: 100%; +} + +.ql-container { + box-sizing: border-box; + width: 100%; + height: 100%; + font-size: 16px; + line-height: 1.5; + overflow: auto; + border: 1px solid #ececec; +} + +.ql-active { + color: #22c704; +} + +.iconfont { + display: inline-block; + width: 30px; + height: 30px; + cursor: pointer; + font-size: 20px; +} + +.toolbar { + box-sizing: border-box; + padding: 0 10px; + height: 50px; + width: 100%; + position: fixed; + left: 0; + right: 100%; + bottom: 0; + display: flex; + align-items: center; + justify-content: space-between; + border: 1px solid #ececec; + border-left: none; + border-right: none; +} diff --git a/xhs-mini-demos/api-case/editor/editor.js b/xhs-mini-demos/api-case/editor/editor.js new file mode 100644 index 0000000..eb94d45 --- /dev/null +++ b/xhs-mini-demos/api-case/editor/editor.js @@ -0,0 +1,226 @@ +const contents = { + html: ` +

支持插入图片

+
+

+ image-alt +

+
+

支持以下字符样式

+

+ bold粗体 + italic斜体 + underline下划线 +

+

+ sub下标 + super上标 +

+
+

支持以下列表样式

+
    +
  1. 有序列表
  2. +
  3. 有序列表
  4. +
+
    +
  • 无序列表
  • +
+
    +
  • 无序列表
  • +
+
    +
  • 选框列表
  • +
+
    +
  • 选框列表
  • +
+
+

支持以下字符大小

+

H1 一级标题

+

H2 二级标题

+

H3 三级标题

+

H4 四级标题

+
H5 五级标题
+
H6 六级标题
+
+

支持以下对齐方式

+

center中间对齐

+

right 右对齐

+

justify 自动对齐

+
+ color 支持设置字体及背景颜色`, +}; +Page({ + onShareAppMessage() { + return { + title: 'editor', + path: 'page/component/pages/editor/editor', + }; + }, + data: { + formats: {}, + readOnly: false, + placeholder: '开始输入...', + editorHeight: 300, + keyboardHeight: 0, + isIOS: false, + safeHeight: 0, + toolBarHeight: 50, + }, + readOnlyChange() { + this.setData({ + readOnly: !this.data.readOnly, + }); + }, + onLoad() { + const { platform, safeArea, model, screenHeight } = xhs.getSystemInfoSync(); + let safeHeight; + if (safeArea) { + safeHeight = screenHeight - safeArea.bottom; + } else { + safeHeight = 32; + } + this._safeHeight = safeHeight; + const isIOS = platform === 'ios'; + this.setData({ isIOS, safeHeight, toolBarHeight: isIOS ? safeHeight + 50 : 50 }); + const that = this; + this.updatePosition(0); + let keyboardHeight = 0; + xhs.onKeyboardHeightChange?.(res => { + if (res.height === keyboardHeight) { + return; + } + const duration = res.height > 0 ? res.duration * 1000 : 0; + keyboardHeight = res.height; + setTimeout(() => { + xhs.pageScrollTo({ + scrollTop: 0, + success() { + that.updatePosition(keyboardHeight); + that.editorCtx.scrollIntoView(); + }, + }); + }, duration); + }); + }, + updatePosition(keyboardHeight) { + const toolbarHeight = 50; + const { windowHeight, platform } = xhs.getSystemInfoSync(); + const editorHeight = + keyboardHeight > 0 ? windowHeight - keyboardHeight - toolbarHeight : windowHeight; + if (keyboardHeight === 0) { + this.setData({ + editorHeight, + keyboardHeight, + toolBarHeight: this.data.isIOS ? 50 + this._safeHeight : 50, + safeHeight: this._safeHeight, + }); + } else { + this.setData({ + editorHeight, + keyboardHeight, + toolBarHeight: 50, + safeHeight: 0, + }); + } + }, + calNavigationBarAndStatusBar() { + const systemInfo = xhs.getSystemInfoSync(); + const { statusBarHeight, platform } = systemInfo; + const isIOS = platform === 'ios'; + const navigationBarHeight = isIOS ? 44 : 48; + return statusBarHeight + navigationBarHeight; + }, + onEditorReady() { + const that = this; + that.editorCtx = xhs.createEditorContext?.('editor'); + this.clear(); + this.setContents(); + this.removeFormat(); + this.insertDivider(); + + setTimeout(() => { + this.editorCtx.getContents({ + success: res => { + console.log('getContents success', res); + }, + }); + }, 1000); + }, + blur() { + this.editorCtx.blur(); + }, + format(e) { + const { name, value } = e.target.dataset; + if (!name) return; + console.log('format', name, value); + this.editorCtx.format(name, value); + }, + onStatusChange(e) { + const formats = e.detail; + console.log('onStatusChange', e); + this.setData({ formats }); + }, + insertDivider() { + this.editorCtx.insertDivider({ + success() { + console.log('insert divider success'); + }, + }); + }, + clear() { + this.editorCtx.clear({ + success(res) { + console.log('clear success', res); + }, + }); + }, + removeFormat() { + this.editorCtx.removeFormat({ + success: res => { + console.log('removeFormat success', res); + }, + }); + }, + setContents() { + this.editorCtx.setContents({ + ...contents, + success: res => { + console.log('setContents success', res); + }, + }); + }, + insertDate() { + const date = new Date(); + const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`; + this.editorCtx.insertText({ + text: formatDate, + }); + }, + insertImage() { + const that = this; + xhs.chooseImage({ + count: 1, + success(res) { + that.editorCtx.insertImage({ + src: res.tempFilePaths[0], + data: { + id: 'abcd', + role: 'god', + }, + width: '80%', + success() { + console.log('insert image success'); + }, + }); + }, + }); + }, + + bindfocus(e) { + console.log('bindfocus', e); + }, + bindblur(e) { + console.log('bindblur', e); + }, +}); diff --git a/xhs-mini-demos/api-case/editor/editor.json b/xhs-mini-demos/api-case/editor/editor.json new file mode 100644 index 0000000..5072d5b --- /dev/null +++ b/xhs-mini-demos/api-case/editor/editor.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "editor", + "disableScroll": true, + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/editor/editor.xhsml b/xhs-mini-demos/api-case/editor/editor.xhsml new file mode 100644 index 0000000..7207ef4 --- /dev/null +++ b/xhs-mini-demos/api-case/editor/editor.xhsml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/ext-config/ext-config.css b/xhs-mini-demos/api-case/ext-config/ext-config.css new file mode 100644 index 0000000..11dc499 --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/ext-config.css @@ -0,0 +1,7 @@ + + +._dflex button{ + margin: 10px 0; + background-color: red; + color: white; +} diff --git a/xhs-mini-demos/api-case/ext-config/ext-config.js b/xhs-mini-demos/api-case/ext-config/ext-config.js new file mode 100644 index 0000000..dabb81a --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/ext-config.js @@ -0,0 +1,23 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + data: { + config: '' + }, + getExtConfig() { + xhs.getExtConfig({ + success: res => { + this.setData({ + content: JSON.stringify(res) + }); + }, + fail: res => {} + }); + }, + getExtConfigSync() { + const data = xhs.getExtConfigSync(); + this.setData({ + content: JSON.stringify(data) + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/ext-config/ext-config.json b/xhs-mini-demos/api-case/ext-config/ext-config.json new file mode 100644 index 0000000..36ac39d --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/ext-config.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "第三方平台", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/ext-config/ext-config.xhsml b/xhs-mini-demos/api-case/ext-config/ext-config.xhsml new file mode 100644 index 0000000..568a219 --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/ext-config.xhsml @@ -0,0 +1,12 @@ + + + + + config: {{content}} + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/ext-config/templates.js b/xhs-mini-demos/api-case/ext-config/templates.js new file mode 100644 index 0000000..429418e --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/templates.js @@ -0,0 +1,84 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.getExtConfig({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, + + page_fun_1() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + let res; + try { + res = xhs.getExtConfigSync() ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/ext-config/templates.xhsml b/xhs-mini-demos/api-case/ext-config/templates.xhsml new file mode 100644 index 0000000..e2171d6 --- /dev/null +++ b/xhs-mini-demos/api-case/ext-config/templates.xhsml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/file/file.css b/xhs-mini-demos/api-case/file/file.css new file mode 100644 index 0000000..94958cb --- /dev/null +++ b/xhs-mini-demos/api-case/file/file.css @@ -0,0 +1,14 @@ +.image { + width: 100%; + height: 330px; +} +.page-body-info { + display: flex; + box-sizing: border-box; + padding: 15px; + height: 410px; + border-top: 1px solid var(--weui-FG-3); + border-bottom: 1px solid var(--weui-FG-3); + align-items: center; + justify-content: center; +} diff --git a/xhs-mini-demos/api-case/file/file.js b/xhs-mini-demos/api-case/file/file.js new file mode 100644 index 0000000..81e39ea --- /dev/null +++ b/xhs-mini-demos/api-case/file/file.js @@ -0,0 +1,133 @@ +Page({ + onShareAppMessage() { + return { + title: '文件', + path: 'packageAPI/pages/file/file', + }; + }, + + onLoad() { + this.setData({ + savedFilePath: xhs.getStorageSync('savedFilePath'), + }); + }, + data: { + tempFilePath: '', + savedFilePath: '', + dialog: { + hidden: true, + }, + filePath: '', + fileType: '', + fileTypes: [ + { + key: 'doc', + value: 'doc格式' + }, + { + key: 'docx', + value: 'docx格式' + }, + { + key: 'xls', + value: 'xls格式' + }, + { + key: 'xlsx', + value: 'xlsx格式' + }, + { + key: 'ppt', + value: 'ppt格式' + }, + { + key: 'pptx', + value: 'pptx格式' + }, + { + key: 'pdf', + value: 'pdf格式' + } + ] + }, + chooseImage() { + const that = this; + xhs.chooseImage({ + count: 1, + success(res) { + that.setData({ + tempFilePath: res.tempFilePaths[0], + }); + }, + }); + }, + saveFile() { + if (this.data.tempFilePath.length > 0) { + const that = this; + xhs.saveFile({ + tempFilePath: this.data.tempFilePath, + success(res) { + that.setData({ + savedFilePath: res.savedFilePath, + }); + xhs.setStorageSync('savedFilePath', res.savedFilePath); + that.setData({ + dialog: { + title: '保存成功', + content: '下次进入应用时,此文件仍可用', + hidden: false, + }, + }); + }, + fail() { + that.setData({ + dialog: { + title: '保存失败', + content: '应该是有 bug 吧', + hidden: false, + }, + }); + }, + }); + } + }, + clear() { + xhs.setStorageSync('savedFilePath', ''); + this.setData({ + tempFilePath: '', + savedFilePath: '', + }); + }, + confirm() { + this.setData({ + 'dialog.hidden': true, + }); + }, + + chooseFile() { + + }, + + openFile() { + console.log(this.data.filePath); + console.log(this.data.fileType); + xhs.openDocument({ + filePath: this.data.filePath, + fileType: this.data.fileType || undefined, + success(res) { + console.log(res); + }, + fail(res) { + console.log(res); + } + }); + }, + + handleFilePath(e) { + this.setData({ filePath: e.detail.value }); + }, + + handleFileType(e) { + this.setData({ fileType: e.detail.value }); + }, +}); diff --git a/xhs-mini-demos/api-case/file/file.json b/xhs-mini-demos/api-case/file/file.json new file mode 100644 index 0000000..173610d --- /dev/null +++ b/xhs-mini-demos/api-case/file/file.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "文件", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/file/file.xhsml b/xhs-mini-demos/api-case/file/file.xhsml new file mode 100644 index 0000000..ce30b5e --- /dev/null +++ b/xhs-mini-demos/api-case/file/file.xhsml @@ -0,0 +1,41 @@ + + + + + 文件类型: + + {{item.key}}:{{item.value}} + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.css b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.css new file mode 100644 index 0000000..e957a0f --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.css @@ -0,0 +1,25 @@ +/* @import '../common/lib/weui.css'; */ +.page-section { + margin-top: 100px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + padding: 0 25px; + box-sizing: border-box; +} +.page-body-title { + font-size: 30px; + line-height: 100px; +} +.page-body-text { + color: #bbb; + font-size: 14px; + line-height: 20px; + margin: 0 0 50px 0; + text-align: center; +} +.page-body-button { + width: 100%; +} diff --git a/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.js b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.js new file mode 100644 index 0000000..378b4a6 --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.js @@ -0,0 +1,21 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: 'get-account-info-sync', + path: 'package/API/pages/get-account-info-sync/get-account-info-sync' + }; + }, + data: { + ret: '', + content: '' + }, + getAccountInfoSync() { + const ret = xhs.getAccountInfoSync(); + this.setData({ + ret: JSON.stringify(ret) + }); + console.log('ret', ret); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.json b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.json new file mode 100644 index 0000000..d06a980 --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取账户信息", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.xhsml b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.xhsml new file mode 100644 index 0000000..c2892be --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/get-account-info-sync.xhsml @@ -0,0 +1,12 @@ + + + + + + 账户信息:{{ret}} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-account-info-sync/templates.js b/xhs-mini-demos/api-case/get-account-info-sync/templates.js new file mode 100644 index 0000000..5e891e7 --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/templates.js @@ -0,0 +1,84 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + let res; + try { + res = xhs.getAccountInfoSync() ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + + page_fun_1() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + xhs.openUserProfile({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/get-account-info-sync/templates.xhsml b/xhs-mini-demos/api-case/get-account-info-sync/templates.xhsml new file mode 100644 index 0000000..d60db03 --- /dev/null +++ b/xhs-mini-demos/api-case/get-account-info-sync/templates.xhsml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/get-battery-info/get-battery-info.css b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/get-battery-info/get-battery-info.js b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.js new file mode 100644 index 0000000..cfd0976 --- /dev/null +++ b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.js @@ -0,0 +1,23 @@ +Page({ + onShareAppMessage() { + return { + title: '获取电池信息', + path: 'packageAPI/pages/get-battery-info/get-battery-info', + }; + }, + data: { + + }, + + getBatteryInfo() { + xhs.getBatteryInfo({ + complete: res => { + const msg = res.isCharging ? '充电中' : '使用电池中'; + this.setData({ + level: res.level, + isCharging: msg, + }); + }, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/get-battery-info/get-battery-info.json b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.json new file mode 100644 index 0000000..4f2df61 --- /dev/null +++ b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.json @@ -0,0 +1,5 @@ +{ + "usingComponents": {}, + "navigationBarTitleText": "获取手机设备电量" + +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-battery-info/get-battery-info.xhsml b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.xhsml new file mode 100644 index 0000000..b4bfc71 --- /dev/null +++ b/xhs-mini-demos/api-case/get-battery-info/get-battery-info.xhsml @@ -0,0 +1,27 @@ + + + + + + + 当前电量 + + + + + + + + 电池模式 + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-location/get-location.css b/xhs-mini-demos/api-case/get-location/get-location.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/get-location/get-location.js b/xhs-mini-demos/api-case/get-location/get-location.js new file mode 100644 index 0000000..a8e776c --- /dev/null +++ b/xhs-mini-demos/api-case/get-location/get-location.js @@ -0,0 +1,200 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '获取位置', + path: 'packageAPI/pages/get-location/get-location' + }; + }, + data: { + count: 0, + hasLocation: false, + altitude: false, + isHighAccuracy: false, + highAccuracyExpireTime: 0, + latitude: 12.1, + longitude: 12.1, + type: 'wgs84', + apiData: { + content: '', + success: false, + fail: false, + complete: false + }, + choosedLocation: { + name: '', + address: '', + latitude: '', + longitude: '' + }, + getLoaction: { + accuracy: '', + altitude: '', + horizontalAccuracy: '', + latitude: '', + longitude: '', + speed: '', + verticalAccuracy: '' + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + getLocation() { + this.resetApiData(); + xhs.getLocation({ + success: res => { + this.setData({ + getLoaction: res + }); + console.log('getlocation', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + startLocationUpdate() { + this.resetApiData(); + xhs.startLocationUpdate({ + success: res => { + this.updateApiData('success', res); + xhs.showToast({ + title: '已开启位置服务' + }); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + startLocationUpdateBackground() { + this.resetApiData(); + xhs.startLocationUpdateBackground({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + stopLocationUpdate() { + this.resetApiData(); + xhs.stopLocationUpdate({ + success: res => { + this.updateApiData('success', res); + xhs.showToast({ + title: '已关闭位置服务' + }); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + chooseLocation() { + this.resetApiData(); + xhs.chooseLocation({ + latitude: this.data.latitude - 0, + longitude: this.data.longitude - 0, + success: res => { + this.setData({ + choosedLocation: res + }); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + onLocationChange() { + this.resetApiData(); + this.offLocation = xhs.onLocationChange(res => { + this.updateApiData('success', res); + this.setData({ + count: this.data.count + 1 + }); + }); + }, + offLocationChange() { + if (this?.offLocation?.remove) { + this.offLocation.remove(); + } + this.updateApiData('success'); + }, + handleAltitude(e) { + this.setData({ + altitude: e.detail.value + }); + }, + handleHighAccuracy(e) { + this.setData({ + isHighAccuracy: e.detail.value + }); + }, + handleHighAccuracyExpireTime(e) { + this.setData({ + highAccuracyExpireTime: e.detail.value - 0 + }); + }, + handleType(e) { + this.setData({ + type: e.detail.value + }); + }, + handleLongitude(e) { + this.setData({ + longitude: e.detail.value - 0 + }); + }, + handleLatitude(e) { + this.setData({ + latitude: e.detail.value - 0 + }); + }, + openLocation() { + xhs.openLocation({ + latitude: 31.215442551782044, + longitude: 121.47457688571865, + address: '上海市黄浦区马当路356号', + name: '小红书总部', + complete: res => { + console.log('【openLocation】:', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-location/get-location.json b/xhs-mini-demos/api-case/get-location/get-location.json new file mode 100644 index 0000000..cfd57a6 --- /dev/null +++ b/xhs-mini-demos/api-case/get-location/get-location.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取位置", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/get-location/get-location.xhsml b/xhs-mini-demos/api-case/get-location/get-location.xhsml new file mode 100644 index 0000000..d4ec0b0 --- /dev/null +++ b/xhs-mini-demos/api-case/get-location/get-location.xhsml @@ -0,0 +1,57 @@ + + + + + 名称:{{choosedLocation.name}} + 地址:{{choosedLocation.address}} + 经度:{{choosedLocation.latitude}} + 纬度:{{choosedLocation.longitude}} + + + + + + + + + + + 纬度:{{getLoaction.latitude}} + 经度:{{getLoaction.longitude}} + 速度:{{getLoaction.speed}} + 位置的精确度:{{getLoaction.accuracy}} + + 高度:{{getLoaction.altitude}} + 垂直精度:{{getLoaction.verticalAccuracy}} + 水平精度:{{getLoaction.horizontalAccuracy}} + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-location/templates.js b/xhs-mini-demos/api-case/get-location/templates.js new file mode 100644 index 0000000..7c8f317 --- /dev/null +++ b/xhs-mini-demos/api-case/get-location/templates.js @@ -0,0 +1,295 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + + page_data_5: false, + + page_data_6: false, + + page_data_7: false, + + page_data_8: "", + + page_data_9: false, + + page_data_10: false, + + page_data_11: false, + + page_data_12: "", + + page_data_13: false, + + page_data_14: false, + + page_data_15: false, + + page_data_16: "", + + page_data_17: "", + + page_data_18: "", + + page_data_19: false, + + page_data_20: false, + + page_data_21: false, + + page_data_22: "", + + page_data_23: "", + + page_data_24: "", + + page_data_25: "", + + page_data_26: "", + + page_data_27: "", + + page_data_28: false, + + page_data_29: false, + + page_data_30: false, + + page_data_31: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.getLocation({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + type: this.data.page_data_0, + }); + }, + + page_fun_2() { + this.setData({ + page_data_5: false, + page_data_6: false, + page_data_7: false, + }); + + xhs.startLocationUpdate({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_5: true, + page_data_8: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_6: true, + page_data_8: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_7: true, + }); + }, + }); + }, + + page_fun_3() { + this.setData({ + page_data_9: false, + page_data_10: false, + page_data_11: false, + }); + + xhs.startLocationUpdateBackground({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_9: true, + page_data_12: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_10: true, + page_data_12: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_11: true, + }); + }, + }); + }, + + page_fun_4() { + this.setData({ + page_data_13: false, + page_data_14: false, + page_data_15: false, + }); + + xhs.stopLocationUpdate({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_13: true, + page_data_16: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_14: true, + page_data_16: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_15: true, + }); + }, + }); + }, + + page_fun_6(e) { + this.setData("page_data_17", e.detail.value); + }, + + page_fun_7(e) { + this.setData("page_data_18", e.detail.value); + }, + + page_fun_5() { + this.setData({ + page_data_19: false, + page_data_20: false, + page_data_21: false, + }); + + xhs.chooseLocation({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_19: true, + page_data_22: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_20: true, + page_data_22: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_21: true, + }); + }, + latitude: this.data.page_data_17, + longitude: this.data.page_data_18, + }); + }, + + page_fun_9(e) { + this.setData("page_data_23", e.detail.value); + }, + + page_fun_10(e) { + this.setData("page_data_24", e.detail.value); + }, + + page_fun_11(e) { + this.setData("page_data_25", e.detail.value); + }, + + page_fun_12(e) { + this.setData("page_data_26", e.detail.value); + }, + + page_fun_13(e) { + this.setData("page_data_27", e.detail.value); + }, + + page_fun_8() { + this.setData({ + page_data_28: false, + page_data_29: false, + page_data_30: false, + }); + + xhs.openLocation({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_28: true, + page_data_31: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_29: true, + page_data_31: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_30: true, + }); + }, + latitude: this.data.page_data_23, + longitude: this.data.page_data_24, + scale: this.data.page_data_25, + name: this.data.page_data_26, + address: this.data.page_data_27, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/get-location/templates.xhsml b/xhs-mini-demos/api-case/get-location/templates.xhsml new file mode 100644 index 0000000..3cfea04 --- /dev/null +++ b/xhs-mini-demos/api-case/get-location/templates.xhsml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/get-network-type/get-network-type.css b/xhs-mini-demos/api-case/get-network-type/get-network-type.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/get-network-type/get-network-type.js b/xhs-mini-demos/api-case/get-network-type/get-network-type.js new file mode 100644 index 0000000..32ef367 --- /dev/null +++ b/xhs-mini-demos/api-case/get-network-type/get-network-type.js @@ -0,0 +1,31 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '获取手机网络状态', + path: 'packageAPI/pages/get-network-type/get-network-type' + }; + }, + data: { + hasNetworkType: false + }, + getNetworkType() { + const that = this; + xhs.getNetworkType({ + success(res) { + console.log(res); + that.setData({ + hasNetworkType: true, + networkType: res.subtype || res.networkType + }); + } + }); + }, + clear() { + this.setData({ + hasNetworkType: false, + networkType: '' + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-network-type/get-network-type.json b/xhs-mini-demos/api-case/get-network-type/get-network-type.json new file mode 100644 index 0000000..50b8182 --- /dev/null +++ b/xhs-mini-demos/api-case/get-network-type/get-network-type.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取手机网络状态", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/get-network-type/get-network-type.xhsml b/xhs-mini-demos/api-case/get-network-type/get-network-type.xhsml new file mode 100644 index 0000000..8643487 --- /dev/null +++ b/xhs-mini-demos/api-case/get-network-type/get-network-type.xhsml @@ -0,0 +1,11 @@ + + + + + 网络状态:{{networkType}} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-network-type/templates.js b/xhs-mini-demos/api-case/get-network-type/templates.js new file mode 100644 index 0000000..c07ce74 --- /dev/null +++ b/xhs-mini-demos/api-case/get-network-type/templates.js @@ -0,0 +1,44 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.getNetworkType({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/get-network-type/templates.xhsml b/xhs-mini-demos/api-case/get-network-type/templates.xhsml new file mode 100644 index 0000000..d0fa1dc --- /dev/null +++ b/xhs-mini-demos/api-case/get-network-type/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/get-system-info/get-system-info.css b/xhs-mini-demos/api-case/get-system-info/get-system-info.css new file mode 100644 index 0000000..9d3c633 --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/get-system-info.css @@ -0,0 +1,8 @@ + +._dflex button { + margin: 10px 0; +} + +._dflex > view { + margin: 6px 0; +} diff --git a/xhs-mini-demos/api-case/get-system-info/get-system-info.js b/xhs-mini-demos/api-case/get-system-info/get-system-info.js new file mode 100644 index 0000000..257549c --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/get-system-info.js @@ -0,0 +1,30 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '获取手机系统信息', + path: '/api-case/get-system-info/get-system-info' + }; + }, + data: { + systemInfo: {} + }, + getSystemInfo() { + xhs.getSystemInfo({ + success: res => { + this.setData({ + systemInfo: res + }); + }, + fail: res => {}, + complete: res => {} + }); + }, + getSystemInfoSync() { + const data = xhs.getSystemInfoSync(); + this.setData({ + systemInfo: data + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-system-info/get-system-info.json b/xhs-mini-demos/api-case/get-system-info/get-system-info.json new file mode 100644 index 0000000..dc083c6 --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/get-system-info.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取手机系统信息", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/get-system-info/get-system-info.xhsml b/xhs-mini-demos/api-case/get-system-info/get-system-info.xhsml new file mode 100644 index 0000000..20f0292 --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/get-system-info.xhsml @@ -0,0 +1,18 @@ + + + + + 手机品牌:{{systemInfo.brand}} + 手机型号:{{systemInfo.model}} + 小红书语言:{{systemInfo.language}} + 小红书版本:{{systemInfo.version}} + 屏幕宽度:{{systemInfo.windowWidth}} + 屏幕高度:{{systemInfo.windowHeight}} + DPR:{{systemInfo.pixelRatio}} + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-system-info/templates.js b/xhs-mini-demos/api-case/get-system-info/templates.js new file mode 100644 index 0000000..899c27f --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/templates.js @@ -0,0 +1,44 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.getSystemInfo({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/get-system-info/templates.xhsml b/xhs-mini-demos/api-case/get-system-info/templates.xhsml new file mode 100644 index 0000000..a184af8 --- /dev/null +++ b/xhs-mini-demos/api-case/get-system-info/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/get-user-info/get-user-info.css b/xhs-mini-demos/api-case/get-user-info/get-user-info.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/get-user-info/get-user-info.js b/xhs-mini-demos/api-case/get-user-info/get-user-info.js new file mode 100644 index 0000000..e18d8c9 --- /dev/null +++ b/xhs-mini-demos/api-case/get-user-info/get-user-info.js @@ -0,0 +1,44 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '获取用户信息', + path: 'packageAPI/pages/get-user-info/get-user-info' + }; + }, + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + }, + info: '' + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + getUserInfo(e) { + this.setData({ + info: JSON.stringify(e) + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-user-info/get-user-info.json b/xhs-mini-demos/api-case/get-user-info/get-user-info.json new file mode 100644 index 0000000..ef04ddd --- /dev/null +++ b/xhs-mini-demos/api-case/get-user-info/get-user-info.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取用户信息", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/get-user-info/get-user-info.xhsml b/xhs-mini-demos/api-case/get-user-info/get-user-info.xhsml new file mode 100644 index 0000000..dc129dd --- /dev/null +++ b/xhs-mini-demos/api-case/get-user-info/get-user-info.xhsml @@ -0,0 +1,16 @@ + + + + + + 用户信息: + {{info}} + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/get-user-info/templates.js b/xhs-mini-demos/api-case/get-user-info/templates.js new file mode 100644 index 0000000..5e2ff81 --- /dev/null +++ b/xhs-mini-demos/api-case/get-user-info/templates.js @@ -0,0 +1,44 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.getUserProfile({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/get-user-info/templates.xhsml b/xhs-mini-demos/api-case/get-user-info/templates.xhsml new file mode 100644 index 0000000..fdf95af --- /dev/null +++ b/xhs-mini-demos/api-case/get-user-info/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.css b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.js b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.js new file mode 100644 index 0000000..ca90678 --- /dev/null +++ b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.js @@ -0,0 +1,3 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.json b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.json new file mode 100644 index 0000000..8545881 --- /dev/null +++ b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "获取小程序启动参数", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.xhsml b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.xhsml new file mode 100644 index 0000000..deb10a0 --- /dev/null +++ b/xhs-mini-demos/api-case/getLaunchOptionsSync/getLaunchOptionsSync.xhsml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.js b/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.js new file mode 100644 index 0000000..da945e8 --- /dev/null +++ b/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.js @@ -0,0 +1,85 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + let res; + try { + res = xhs.getLaunchOptionsSync() ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + + page_fun_1() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + let res; + try { + res = xhs.getEnterOptionsSync() ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.xhsml b/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.xhsml new file mode 100644 index 0000000..0b5d1c4 --- /dev/null +++ b/xhs-mini-demos/api-case/getLaunchOptionsSync/templates.xhsml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/hide-home-button/hide-home-button.css b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.css new file mode 100644 index 0000000..0642f8d --- /dev/null +++ b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.css @@ -0,0 +1 @@ +/* @import '../common/lib/weui.css'; */ diff --git a/xhs-mini-demos/api-case/hide-home-button/hide-home-button.js b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.js new file mode 100644 index 0000000..53e46dd --- /dev/null +++ b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.js @@ -0,0 +1,43 @@ +Page({ + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false, + }, + }, + + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '', + }, + }); + }, + + updateApiData(type, content) { + const apiData = { ...this.data.apiData }; + apiData[type] = true; + apiData.content = content; + this.setData({ apiData }); + }, + + hideHomeButton() { + this.resetApiData(); + xhs.hideHomeButton({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/hide-home-button/hide-home-button.json b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.json new file mode 100644 index 0000000..bcaaef6 --- /dev/null +++ b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "隐藏返回首页按钮", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/hide-home-button/hide-home-button.xhsml b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.xhsml new file mode 100644 index 0000000..ffea3b6 --- /dev/null +++ b/xhs-mini-demos/api-case/hide-home-button/hide-home-button.xhsml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/image/image.css b/xhs-mini-demos/api-case/image/image.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/image/image.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/image/image.js b/xhs-mini-demos/api-case/image/image.js new file mode 100644 index 0000000..fb8d762 --- /dev/null +++ b/xhs-mini-demos/api-case/image/image.js @@ -0,0 +1,98 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +const sourceType = [['camera'], ['album'], ['camera', 'album']]; +const sizeType = [['compressed'], ['original'], ['compressed', 'original']]; +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '图片', + path: 'packageAPI/pages/image/image' + }; + }, + data: { + imageList: [], + sourceTypeIndex: 2, + sourceType: ['拍照', '相册', '拍照或相册'], + sizeTypeIndex: 2, + sizeType: ['压缩', '原图', '压缩或原图'], + countIndex: 8, + count: [1, 2, 3, 4, 5, 6, 7, 8, 9], + saveImageToPhotosAlbumLink: '/image/green_tri.png', + imageInfo: '' + }, + sourceTypeChange(e) { + this.setData({ + sourceTypeIndex: e.detail.value + }); + }, + sizeTypeChange(e) { + this.setData({ + sizeTypeIndex: e.detail.value + }); + }, + countChange(e) { + this.setData({ + countIndex: e.detail.value + }); + }, + chooseImage() { + const that = this; + xhs.chooseImage({ + sourceType: sourceType[this.data.sourceTypeIndex], + sizeType: sizeType[this.data.sizeTypeIndex], + count: this.data.count[this.data.countIndex], + success: res => { + that.setData({ + imageList: [...this.data.imageList, ...res.tempFilePaths].slice(-9) + }); + console.log(res); + }, + fail: res => {} + }); + }, + previewImage(e) { + const current = e.target.dataset.src; + xhs.previewImage({ + current, + urls: this.data.imageList, + success: res => {}, + fail: res => {} + }); + }, + previewImageStatic() { + this.resetApiData(); + xhs.previewImage({ + current: 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/yinyue@2x-c18adacacb.png', + urls: ['https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/yinyue@2x-c18adacacb.png', 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/baike@2x-1fe3db7fa6.png', 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/zhidao@2x-e9b427ecc4.png'], + success: res => {}, + fail: res => {} + }); + }, + handleSaveImageToPhotosAlbumLink(e) { + this.setData({ + saveImageToPhotosAlbumLink: e.detail.value + }); + }, + saveImageToPhotosAlbum() { + xhs.saveImageToPhotosAlbum({ + filePath: this.data.saveImageToPhotosAlbumLink, + success: res => { + console.log(res); + }, + fail: res => { + console.log(res); + } + }); + }, + getImageInfo() { + xhs.getImageInfo({ + src: 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/yinyue@2x-c18adacacb.png', + success: res => { + this.setData({ + imageInfo: JSON.stringify(res) + }); + }, + fail: res => {} + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/image/image.json b/xhs-mini-demos/api-case/image/image.json new file mode 100644 index 0000000..7bf5ab7 --- /dev/null +++ b/xhs-mini-demos/api-case/image/image.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "图片", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/image/image.xhsml b/xhs-mini-demos/api-case/image/image.xhsml new file mode 100644 index 0000000..62a58fb --- /dev/null +++ b/xhs-mini-demos/api-case/image/image.xhsml @@ -0,0 +1,65 @@ + +
+ + + + + + 图片来源: {{sourceType[sourceTypeIndex]}} + + + + + + 图片质量: {{sizeType[sizeTypeIndex]}} + + + + + + 数量限制: {{count[countIndex]}} + + + + + 点击可预览选好的图片({{imageList.length}}/{{count[countIndex]}}) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{imageInfo}} + + + + +
+
+ \ No newline at end of file diff --git a/xhs-mini-demos/api-case/image/templates.js b/xhs-mini-demos/api-case/image/templates.js new file mode 100644 index 0000000..3a18c3e --- /dev/null +++ b/xhs-mini-demos/api-case/image/templates.js @@ -0,0 +1,217 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: false, + + page_data_4: false, + + page_data_5: false, + + page_data_6: "", + + page_data_7: "", + + page_data_8: "", + + page_data_9: "", + + page_data_10: false, + + page_data_11: false, + + page_data_12: false, + + page_data_13: "", + + page_data_14: "", + + page_data_15: false, + + page_data_16: false, + + page_data_17: false, + + page_data_18: "", + + page_data_19: "", + + page_data_20: false, + + page_data_21: false, + + page_data_22: false, + + page_data_23: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_3: false, + page_data_4: false, + page_data_5: false, + }); + + xhs.chooseImage({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_3: true, + page_data_6: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_4: true, + page_data_6: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_5: true, + }); + }, + count: this.data.page_data_0, + sizeType: this.data.page_data_1, + sourceType: this.data.page_data_2, + }); + }, + + page_fun_5(e) { + this.setData("page_data_7", e.detail.value); + }, + + page_fun_6(e) { + this.setData("page_data_8", e.detail.value); + }, + + page_fun_7(e) { + this.setData("page_data_9", e.detail.value); + }, + + page_fun_4() { + this.setData({ + page_data_10: false, + page_data_11: false, + page_data_12: false, + }); + + xhs.previewImage({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_10: true, + page_data_13: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_11: true, + page_data_13: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_12: true, + }); + }, + urls: this.data.page_data_7, + showmenu: this.data.page_data_8, + current: this.data.page_data_9, + }); + }, + + page_fun_9(e) { + this.setData("page_data_14", e.detail.value); + }, + + page_fun_8() { + this.setData({ + page_data_15: false, + page_data_16: false, + page_data_17: false, + }); + + xhs.saveImageToPhotosAlbum({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_15: true, + page_data_18: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_16: true, + page_data_18: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_17: true, + }); + }, + filePath: this.data.page_data_14, + }); + }, + + page_fun_11(e) { + this.setData("page_data_19", e.detail.value); + }, + + page_fun_10() { + this.setData({ + page_data_20: false, + page_data_21: false, + page_data_22: false, + }); + + xhs.getImageInfo({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_20: true, + page_data_23: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_21: true, + page_data_23: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_22: true, + }); + }, + src: this.data.page_data_19, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/image/templates.xhsml b/xhs-mini-demos/api-case/image/templates.xhsml new file mode 100644 index 0000000..8e714fc --- /dev/null +++ b/xhs-mini-demos/api-case/image/templates.xhsml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 是否开启showmenu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/lifetime/lifetime.css b/xhs-mini-demos/api-case/lifetime/lifetime.css new file mode 100644 index 0000000..f7eea81 --- /dev/null +++ b/xhs-mini-demos/api-case/lifetime/lifetime.css @@ -0,0 +1,16 @@ +.lifetime-message { + max-height: 400px; +} + +.lifetime-message .lifetime-message-item { + display: flex; + justify-content: space-between; + align-items: center; +} + +.lifetime-message .lifetime-message-item text { + padding: 0 10px; + border-radius: 100px; + background-color: red; + color: white; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/lifetime/lifetime.js b/xhs-mini-demos/api-case/lifetime/lifetime.js new file mode 100644 index 0000000..0b96df6 --- /dev/null +++ b/xhs-mini-demos/api-case/lifetime/lifetime.js @@ -0,0 +1,89 @@ +let messageCount = 0; + +Page({ + data: { + message: [], + height: '0', + scrollTop: 0 + }, + + onLoad() { + this.pushMessage('onLoad'); + }, + onShow() { + this.pushMessage('onShow'); + }, + onReady() { + this.pushMessage('onReady'); + }, + onHide() { + this.pushMessage('onHide'); + }, + onUnload() { + this.pushMessage('onUnload'); + }, + onPullDownRefresh() { + this.pushMessage('onPullDownRefresh'); + }, + onReachBottom() { + this.pushMessage('onReachBottom'); + }, + onShareAppMessage() { + this.pushMessage('onShareAppMessage'); + }, + onShareTimeline() { + this.pushMessage('onShareTimeline'); + }, + onShareChat() { + this.pushMessage('onShareChat'); + }, + onPageScroll() { + this.pushMessage('onPageScroll'); + }, + onTabItemTap() { + this.pushMessage('onTabItemTap'); + }, + + pushMessage(name) { + const msg = this.data.message; + if (!msg.length) { + this.setData('message', [{lifeName: name, count: 1}]); + return; + } + + const last = msg[msg.length - 1]; + + if (last.lifeName === name) { + last.count++; + this.setData('message', [...msg]); + return; + } + messageCount++; + this.scrollToBottom(); + this.setData({ + message: [...msg, {lifeName: name, count: 1}] + }); + }, + + startPullDownRefresh() { + xhs.startPullDownRefresh(); + }, + + stopPullDownRefresh() { + xhs.stopPullDownRefresh(); + }, + + generateBox() { + this.setData('height', '50vh'); + }, + + notGenerateBox() { + this.setData('height', '0'); + }, + + scrollToBottom() { + this.setData({ + scrollTop: 100 * messageCount + }); + } +}); diff --git a/xhs-mini-demos/api-case/lifetime/lifetime.json b/xhs-mini-demos/api-case/lifetime/lifetime.json new file mode 100644 index 0000000..89442d6 --- /dev/null +++ b/xhs-mini-demos/api-case/lifetime/lifetime.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "生命周期", + "enablePullDownRefresh": true, + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/lifetime/lifetime.xhsml b/xhs-mini-demos/api-case/lifetime/lifetime.xhsml new file mode 100644 index 0000000..7335d1e --- /dev/null +++ b/xhs-mini-demos/api-case/lifetime/lifetime.xhsml @@ -0,0 +1,36 @@ + + + + + + + + {{item.count}}次 + 触发了{{item.lifeName}}事件 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/loading/loading.css b/xhs-mini-demos/api-case/loading/loading.css new file mode 100644 index 0000000..78b1d58 --- /dev/null +++ b/xhs-mini-demos/api-case/loading/loading.css @@ -0,0 +1,5 @@ + + +.loading-container button { + margin: 20px 0; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/loading/loading.js b/xhs-mini-demos/api-case/loading/loading.js new file mode 100644 index 0000000..c25ded0 --- /dev/null +++ b/xhs-mini-demos/api-case/loading/loading.js @@ -0,0 +1,86 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: 'loading弹窗', + path: 'packageAPI/pages/loading/loading' + }; + }, + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + common(config) { + this.resetApiData(); + xhs.showLoading({ + ...config, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + title() { + this.common({ + title: 'loading' + }); + }, + fail() { + this.common({ + title: '自定义文案' + }); + }, + mask() { + this.common({ + title: 'loading', + mask: true + }); + setTimeout(() => { + xhs.hideLoading({}); + }, 2000); + }, + hide() { + this.resetApiData(); + xhs.hideLoading({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/loading/loading.json b/xhs-mini-demos/api-case/loading/loading.json new file mode 100644 index 0000000..1aae034 --- /dev/null +++ b/xhs-mini-demos/api-case/loading/loading.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "加载动画框", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/loading/loading.xhsml b/xhs-mini-demos/api-case/loading/loading.xhsml new file mode 100644 index 0000000..931bf67 --- /dev/null +++ b/xhs-mini-demos/api-case/loading/loading.xhsml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/loading/templates.js b/xhs-mini-demos/api-case/loading/templates.js new file mode 100644 index 0000000..965df6e --- /dev/null +++ b/xhs-mini-demos/api-case/loading/templates.js @@ -0,0 +1,97 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: false, + + page_data_3: false, + + page_data_4: false, + + page_data_5: "", + + page_data_6: false, + + page_data_7: false, + + page_data_8: false, + + page_data_9: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_2: false, + page_data_3: false, + page_data_4: false, + }); + + xhs.showLoading({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_2: true, + page_data_5: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_3: true, + page_data_5: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_4: true, + }); + }, + title: this.data.page_data_0, + mask: this.data.page_data_1, + }); + }, + + page_fun_3() { + this.setData({ + page_data_6: false, + page_data_7: false, + page_data_8: false, + }); + + xhs.hideLoading({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_6: true, + page_data_9: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_7: true, + page_data_9: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_8: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/loading/templates.xhsml b/xhs-mini-demos/api-case/loading/templates.xhsml new file mode 100644 index 0000000..d993914 --- /dev/null +++ b/xhs-mini-demos/api-case/loading/templates.xhsml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + 是否开启mask + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/login/login.css b/xhs-mini-demos/api-case/login/login.css new file mode 100644 index 0000000..9a8913b --- /dev/null +++ b/xhs-mini-demos/api-case/login/login.css @@ -0,0 +1,33 @@ +.page-section { + margin-top: 100px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + padding: 0 25px; + box-sizing: border-box; +} +.page-body-title { + font-size: 30px; + line-height: 100px; +} +.page-body-text { + color: #bbb; + font-size: 14px; + line-height: 20px; + margin: 0 0 50px 0; + text-align: center; +} +.page-body-button { + width: 100%; +} + +.info { + text-align: center; +} + +.input { + height: 40px; + padding: 10px; +} diff --git a/xhs-mini-demos/api-case/login/login.js b/xhs-mini-demos/api-case/login/login.js new file mode 100644 index 0000000..f77c28c --- /dev/null +++ b/xhs-mini-demos/api-case/login/login.js @@ -0,0 +1,39 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +const app = getApp(); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '小红书登录', + path: 'package/API/pages/login/login' + }; + }, + data: { + timeout: 3000, + hasLogin: false + }, + onLoad() { + this.setData({ + hasLogin: app.globalData.hasLogin + }); + }, + login() { + if (app.globalData.hasLogin) { + xhs.showToast({ + title: '您已登陆' + }); + return; + } + xhs.login({ + timeout: this.timeout, + success: res => { + app.globalData.hasLogin = true; + this.setData({ + hasLogin: true + }); + }, + fail: res => {}, + complete: res => {} + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/login/login.json b/xhs-mini-demos/api-case/login/login.json new file mode 100644 index 0000000..3bb68f5 --- /dev/null +++ b/xhs-mini-demos/api-case/login/login.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "小红书登录", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/login/login.xhsml b/xhs-mini-demos/api-case/login/login.xhsml new file mode 100644 index 0000000..1d647eb --- /dev/null +++ b/xhs-mini-demos/api-case/login/login.xhsml @@ -0,0 +1,11 @@ + + + + + {{hasLogin === true ? '已登录':'未登录'}} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/login/templates.js b/xhs-mini-demos/api-case/login/templates.js new file mode 100644 index 0000000..1e9fc38 --- /dev/null +++ b/xhs-mini-demos/api-case/login/templates.js @@ -0,0 +1,51 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.login({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + timeout: this.data.page_data_0, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/login/templates.xhsml b/xhs-mini-demos/api-case/login/templates.xhsml new file mode 100644 index 0000000..73c8578 --- /dev/null +++ b/xhs-mini-demos/api-case/login/templates.xhsml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/make-phone-call/make-phone-call.css b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/make-phone-call/make-phone-call.js b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.js new file mode 100644 index 0000000..bba053c --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.js @@ -0,0 +1,66 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '打电话', + path: 'packageAPI/pages/make-phone-call/make-phone-call' + }; + }, + data: { + disabled: true, + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + bindInput(e) { + this.inputValue = e.detail.value; + if (this.inputValue.length > 0) { + this.setData({ + disabled: false + }); + } else { + this.setData({ + disabled: true + }); + } + }, + makePhoneCall() { + this.resetApiData(); + xhs.makePhoneCall({ + phoneNumber: this.inputValue, + success: e => { + this.updateApiData('success', e); + }, + fail: e => { + this.updateApiData('fail', e); + }, + complete: e => { + this.updateApiData('complete', e); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/make-phone-call/make-phone-call.json b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.json new file mode 100644 index 0000000..c64eb09 --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "打电话", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/make-phone-call/make-phone-call.xhsml b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.xhsml new file mode 100644 index 0000000..f3eda33 --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/make-phone-call.xhsml @@ -0,0 +1,16 @@ + + + + + 请在下方输入电话号码: + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/make-phone-call/templates.js b/xhs-mini-demos/api-case/make-phone-call/templates.js new file mode 100644 index 0000000..edb6928 --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/templates.js @@ -0,0 +1,51 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.makePhoneCall({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + phoneNumber: this.data.page_data_0, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/make-phone-call/templates.xhsml b/xhs-mini-demos/api-case/make-phone-call/templates.xhsml new file mode 100644 index 0000000..80bab0a --- /dev/null +++ b/xhs-mini-demos/api-case/make-phone-call/templates.xhsml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/map/map.css b/xhs-mini-demos/api-case/map/map.css new file mode 100644 index 0000000..d0fe45d --- /dev/null +++ b/xhs-mini-demos/api-case/map/map.css @@ -0,0 +1,10 @@ + +._cred { + display: inline; +} + +._dflex button { + margin: 10px 0; + background-color: red; + color: white; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/map/map.js b/xhs-mini-demos/api-case/map/map.js new file mode 100644 index 0000000..b6579a7 --- /dev/null +++ b/xhs-mini-demos/api-case/map/map.js @@ -0,0 +1,150 @@ +Page({ + onShareAppMessage() { + return { + title: 'map', + path: 'page/component/pages/map/map', + }; + }, + + data: { + latitude: 31.215815, + longitude: 121.474845, + markers: [ + { + latitude: 23.099994, + longitude: 113.32452, + name: 'T.I.T 创意园', + id: '1', + callout: { + content: 'ALWAYS callout', + color: 'red', + }, + }, + { + id: '2', + latitude: 23.099, + longitude: 113.324, + name: 'BYCLICK callout', + callout: { + content: 'BYCLICK', + color: 'red', + }, + }, + ], + covers: [ + { + latitude: 23.099994, + longitude: 113.34452, + iconPath: '/image/location.png', + }, + { + latitude: 23.099994, + longitude: 113.30452, + iconPath: '/image/location.png', + }, + ], + polygons: [ + { + points: [ + { + latitude: 23.099994, + longitude: 113.32452, + }, + { + latitude: 23.098994, + longitude: 113.32352, + }, + { + latitude: 23.098994, + longitude: 113.32552, + }, + ], + strokeWidth: 3, + strokeColor: '#FFFFFFAA', + }, + ], + subKey: 'B5QBZ-7JTLU-DSSVA-2BRJ3-TNXLF-2TBR7', + enable3d: false, + showCompass: false, + enableOverlooking: false, + enableZoom: true, + enableScroll: true, + enableRotate: false, + drawPolygon: false, + enableSatellite: false, + enableTraffic: false, + }, + toggle3d() { + this.setData({ + enable3d: !this.data.enable3d, + }); + }, + toggleShowCompass() { + this.setData({ + showCompass: !this.data.showCompass, + }); + }, + toggleOverlooking() { + this.setData({ + enableOverlooking: !this.data.enableOverlooking, + }); + }, + toggleZoom() { + this.setData({ + enableZoom: !this.data.enableZoom, + }); + }, + toggleScroll() { + this.setData({ + enableScroll: !this.data.enableScroll, + }); + }, + toggleRotate() { + this.setData({ + enableRotate: !this.data.enableRotate, + }); + }, + togglePolygon() { + this.setData({ + drawPolygon: !this.data.drawPolygon, + }); + }, + toggleSatellite() { + this.setData({ + enableSatellite: !this.data.enableSatellite, + }); + }, + toggleTraffic() { + this.setData({ + enableTraffic: !this.data.enableTraffic, + }); + }, + onReady() { + setTimeout(() => { + this.mapContext = xhs.createMapContext('mapId'); + this.mapContext?.getScale({ + success: console.log, + }); + this.mapContext?.getRegion({ + success: console.log, + fail: console.error, + }); + this.mapContext?.includePoints({ + success: console.log, + fail: console.error, + }); + }, 5000); + }, + bindtap(e) { + console.log('bindtap ===>', e); + }, + bindmarkertap(e) { + console.log('bindmarkertap ==>', e); + }, + bindcallouttap(e) { + console.log('bindcallouttap ==>', e); + }, + bindlabeltap(e) { + console.log('bindlabeltap ===>', e); + }, +}); diff --git a/xhs-mini-demos/api-case/map/map.json b/xhs-mini-demos/api-case/map/map.json new file mode 100644 index 0000000..fda5191 --- /dev/null +++ b/xhs-mini-demos/api-case/map/map.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "地图", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/map/map.xhsml b/xhs-mini-demos/api-case/map/map.xhsml new file mode 100644 index 0000000..7d49e78 --- /dev/null +++ b/xhs-mini-demos/api-case/map/map.xhsml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/memory-warn/memory-warn.css b/xhs-mini-demos/api-case/memory-warn/memory-warn.css new file mode 100644 index 0000000..d9df9b7 --- /dev/null +++ b/xhs-mini-demos/api-case/memory-warn/memory-warn.css @@ -0,0 +1,24 @@ +.page-section { + margin-top: 100px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + padding: 0 25px; + box-sizing: border-box; +} +.page-body-title { + font-size: 30px; + line-height: 100px; +} +.page-body-text { + color: #bbb; + font-size: 14px; + line-height: 20px; + margin: 0 0 50px 0; + text-align: center; +} +.page-body-button { + width: 100%; +} diff --git a/xhs-mini-demos/api-case/memory-warn/memory-warn.js b/xhs-mini-demos/api-case/memory-warn/memory-warn.js new file mode 100644 index 0000000..6cfe627 --- /dev/null +++ b/xhs-mini-demos/api-case/memory-warn/memory-warn.js @@ -0,0 +1,42 @@ +Page({ + onShareAppMessage() { + return { + title: 'memory-warn', + path: 'package/API/pages/memory-warn/memory-warn', + }; + }, + + data: { + value: '', + memory: [], + }, + resetValue() { + this.setData({ value: '' }); + }, + bindSubscribe() { + this.resetValue(); + xhs.onMemoryWarning(e => { + this.setData({ value: JSON.stringify(e) }); + }); + this.setData({ value: '订阅成功' }); + }, + bindUnSubscribe() { + this.resetValue(); + xhs.offMemoryWarning(() => { + this.setData({ value: '取消成功' }); + }); + }, + bindMemory() { + if (this.handle) { + clearInterval(this.handle); + } else { + this.handle = setInterval(() => { + const { memory } = this.data; + for (let i = 0; i < 100; i++) { + memory.push({ name: 'test', age: 20 }); + } + this.setData({ memory }); + }, 1000); + } + }, +}); diff --git a/xhs-mini-demos/api-case/memory-warn/memory-warn.json b/xhs-mini-demos/api-case/memory-warn/memory-warn.json new file mode 100644 index 0000000..9bea7f8 --- /dev/null +++ b/xhs-mini-demos/api-case/memory-warn/memory-warn.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "memory-warn", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/memory-warn/memory-warn.xhsml b/xhs-mini-demos/api-case/memory-warn/memory-warn.xhsml new file mode 100644 index 0000000..256194a --- /dev/null +++ b/xhs-mini-demos/api-case/memory-warn/memory-warn.xhsml @@ -0,0 +1,13 @@ + + + + + 响应:{{value}} + 数组长度:{{memory.length}} + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/menu-button/menu-button.css b/xhs-mini-demos/api-case/menu-button/menu-button.css new file mode 100644 index 0000000..9a8913b --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/menu-button.css @@ -0,0 +1,33 @@ +.page-section { + margin-top: 100px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + padding: 0 25px; + box-sizing: border-box; +} +.page-body-title { + font-size: 30px; + line-height: 100px; +} +.page-body-text { + color: #bbb; + font-size: 14px; + line-height: 20px; + margin: 0 0 50px 0; + text-align: center; +} +.page-body-button { + width: 100%; +} + +.info { + text-align: center; +} + +.input { + height: 40px; + padding: 10px; +} diff --git a/xhs-mini-demos/api-case/menu-button/menu-button.js b/xhs-mini-demos/api-case/menu-button/menu-button.js new file mode 100644 index 0000000..d948663 --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/menu-button.js @@ -0,0 +1,26 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: 'menu-button', + path: 'api-case/menu-button/menu-button' + }; + }, + data: { + context: '' + }, + getMenuButtonBoundingClientRect() { + const res = xhs.getMenuButtonBoundingClientRect(); + if (res.errMsg) { + xhs.showToast({ + title: `调用失败:${res.errMsg}`, + duration: 2000 + }); + return; + } + this.setData({ + content: JSON.stringify(res) + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/menu-button/menu-button.json b/xhs-mini-demos/api-case/menu-button/menu-button.json new file mode 100644 index 0000000..5c90e80 --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/menu-button.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "菜单按钮", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/menu-button/menu-button.xhsml b/xhs-mini-demos/api-case/menu-button/menu-button.xhsml new file mode 100644 index 0000000..e86c039 --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/menu-button.xhsml @@ -0,0 +1,11 @@ + + + + + 结果:{{content}} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/menu-button/templates.js b/xhs-mini-demos/api-case/menu-button/templates.js new file mode 100644 index 0000000..ac44175 --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/templates.js @@ -0,0 +1,45 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + let res; + try { + res = xhs.getMenuButtonBoundingClientRect() ?? "无返回值"; + } catch (err) { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + + return; + } + + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/menu-button/templates.xhsml b/xhs-mini-demos/api-case/menu-button/templates.xhsml new file mode 100644 index 0000000..96a0b6f --- /dev/null +++ b/xhs-mini-demos/api-case/menu-button/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/modal/modal.css b/xhs-mini-demos/api-case/modal/modal.css new file mode 100644 index 0000000..78adcd8 --- /dev/null +++ b/xhs-mini-demos/api-case/modal/modal.css @@ -0,0 +1,30 @@ + +.btn-area > view { + margin-bottom: 20px; +} + +.model-title { + font-size: 12px; + padding-bottom: 16px; + color: #333333; + display: flex; + justify-content: space-between; + align-items: baseline; +} + +.model-title text:first-child { + font-size: 14px; + font-weight: 400; +} + +.model-title text:last-child { + color: #858585; +} + +.setting-title { + font-size: 12px; + padding-bottom: 16px; + color: #858585; + text-align: center; +} + diff --git a/xhs-mini-demos/api-case/modal/modal.js b/xhs-mini-demos/api-case/modal/modal.js new file mode 100644 index 0000000..7882ee9 --- /dev/null +++ b/xhs-mini-demos/api-case/modal/modal.js @@ -0,0 +1,132 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '模态弹窗', + path: 'packageAPI/pages/modal/modal' + }; + }, + data: { + title: '弹窗标题', + content: '弹框内容', + cancelText: '取消文字', + cancelTextColor: '#ff0000', + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + handleTitleInput(e) { + this.setData({ + title: e.detail.value + }); + }, + handleContentInput(e) { + this.setData({ + content: e.detail.value + }); + }, + handleCancelTextInput(e) { + this.setData({ + cancelText: e.detail.value + }); + }, + handleCancelTextColorInput(e) { + this.setData({ + cancelTextColor: e.detail.value + }); + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + common(config) { + this.resetApiData(); + xhs.showModal({ + ...config, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + noTitlemodalTap() { + this.common({ + content: this.data.content, + showCancel: false + }); + }, + modalTap() { + this.common({ + title: this.data.title + }); + }, + modalTap1() { + this.common({ + title: this.data.title, + showCancel: false + }); + }, + modalTap2() { + this.common({ + title: this.data.title, + cancelText: this.data.cancelText + }); + }, + modalTap3() { + this.common({ + title: this.data.title, + cancelColor: this.data.cancelTextColor + }); + }, + modalTap4() { + this.common({ + title: this.data.title, + confirmText: '确认文字' + }); + }, + modalTap5() { + this.common({ + title: this.data.title, + confirmColor: '#00ff00' + }); + }, + modalTap6() { + this.common({ + title: this.data.title, + editable: true, + placeholderText: 'placeholderText' + }); + }, + modalTap7() { + this.common({ + title: this.data.title, + editable: true, + placeholderText: 'this is default' + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/modal/modal.json b/xhs-mini-demos/api-case/modal/modal.json new file mode 100644 index 0000000..18421d3 --- /dev/null +++ b/xhs-mini-demos/api-case/modal/modal.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "模态弹窗", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/modal/modal.xhsml b/xhs-mini-demos/api-case/modal/modal.xhsml new file mode 100644 index 0000000..756e172 --- /dev/null +++ b/xhs-mini-demos/api-case/modal/modal.xhsml @@ -0,0 +1,39 @@ + + + + + + + 带标题的双操作弹窗 + 点击下方按钮触发 + + + + + + 带标题的单操作弹窗 + 点击下方按钮触发 + + + + + + + 无标题的单操作弹窗 + 点击下方按钮触发 + + + + + + + + + + 点击下方按钮触发 + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/modal/templates.js b/xhs-mini-demos/api-case/modal/templates.js new file mode 100644 index 0000000..80c9580 --- /dev/null +++ b/xhs-mini-demos/api-case/modal/templates.js @@ -0,0 +1,107 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: "", + + page_data_4: "", + + page_data_5: "", + + page_data_6: "", + + page_data_7: "", + + page_data_8: "", + + page_data_9: false, + + page_data_10: false, + + page_data_11: false, + + page_data_12: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_4(e) { + this.setData("page_data_3", e.detail.value); + }, + + page_fun_5(e) { + this.setData("page_data_4", e.detail.value); + }, + + page_fun_6(e) { + this.setData("page_data_5", e.detail.value); + }, + + page_fun_7(e) { + this.setData("page_data_6", e.detail.value); + }, + + page_fun_8(e) { + this.setData("page_data_7", e.detail.value); + }, + + page_fun_9(e) { + this.setData("page_data_8", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_9: false, + page_data_10: false, + page_data_11: false, + }); + + xhs.showModal({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_9: true, + page_data_12: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_10: true, + page_data_12: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_11: true, + }); + }, + title: this.data.page_data_0, + content: this.data.page_data_1, + showCancel: this.data.page_data_2, + cancelText: this.data.page_data_3, + cancelColor: this.data.page_data_4, + confirmText: this.data.page_data_5, + confirmColor: this.data.page_data_6, + editable: this.data.page_data_7, + placeholderText: this.data.page_data_8, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/modal/templates.xhsml b/xhs-mini-demos/api-case/modal/templates.xhsml new file mode 100644 index 0000000..f40aedf --- /dev/null +++ b/xhs-mini-demos/api-case/modal/templates.xhsml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + 是否开启showCancel + + + + + + + + + + + + + + + + + + + + + 是否开启editable + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/mp-update/mp-update.css b/xhs-mini-demos/api-case/mp-update/mp-update.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/mp-update/mp-update.js b/xhs-mini-demos/api-case/mp-update/mp-update.js new file mode 100644 index 0000000..b8f2ede --- /dev/null +++ b/xhs-mini-demos/api-case/mp-update/mp-update.js @@ -0,0 +1,21 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + data: { + shouldUpdate: '' + }, + handleCheckUpdate(e) { + this.setData({ + shouldUpdate: false + }); + }, + onLoad() { + const updateManager = xhs.getUpdateManager(); + updateManager.onCheckForUpdate(res => { + xhs.showModal({ + title: '提示', + content: JSON.stringify(res) + }); + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/mp-update/mp-update.json b/xhs-mini-demos/api-case/mp-update/mp-update.json new file mode 100644 index 0000000..bebcf73 --- /dev/null +++ b/xhs-mini-demos/api-case/mp-update/mp-update.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "检测小程序更新", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/mp-update/mp-update.xhsml b/xhs-mini-demos/api-case/mp-update/mp-update.xhsml new file mode 100644 index 0000000..6e75884 --- /dev/null +++ b/xhs-mini-demos/api-case/mp-update/mp-update.xhsml @@ -0,0 +1,11 @@ + + + + + 返回值:{{ shouldUpdate }} + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/mp-update/templates.js b/xhs-mini-demos/api-case/mp-update/templates.js new file mode 100644 index 0000000..cd0a3cb --- /dev/null +++ b/xhs-mini-demos/api-case/mp-update/templates.js @@ -0,0 +1,46 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + }, + + page_fun_0() { + const updateManager = xhs.getUpdateManager(); + + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + updateManager.applyUpdate({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/mp-update/templates.xhsml b/xhs-mini-demos/api-case/mp-update/templates.xhsml new file mode 100644 index 0000000..3c7f695 --- /dev/null +++ b/xhs-mini-demos/api-case/mp-update/templates.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.css b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.js b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.js new file mode 100644 index 0000000..1581fd8 --- /dev/null +++ b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.js @@ -0,0 +1,15 @@ +Page({ + onShareAppMessage() { + return { + title: '标题栏加载动画', + path: 'packageAPI/pages/navigation-bar-loading/navigation-bar-loading', + }; + }, + + showNavigationBarLoading() { + xhs.showNavigationBarLoading(); + }, + hideNavigationBarLoading() { + xhs.hideNavigationBarLoading(); + }, +}); diff --git a/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.json b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.json new file mode 100644 index 0000000..725f8ed --- /dev/null +++ b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "标题栏加载动画" +} diff --git a/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.xhsml b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.xhsml new file mode 100644 index 0000000..d5372a1 --- /dev/null +++ b/xhs-mini-demos/api-case/navigation-bar-loading/navigation-bar-loading.xhsml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/xhs-mini-demos/api-case/navigator/navigate.css b/xhs-mini-demos/api-case/navigator/navigate.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/navigator/navigate.js b/xhs-mini-demos/api-case/navigator/navigate.js new file mode 100644 index 0000000..1987c9c --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigate.js @@ -0,0 +1,118 @@ +Page({ + onShareAppMessage() { + return { + title: 'navigatePage', + path: 'page/component/pages/navigator/navigate', + }; + }, + + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false, + }, + }, + + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '', + }, + }); + }, + + updateApiData(type, content) { + const apiData = { ...this.data.apiData }; + apiData[type] = true; + apiData.content = `${content}`; + this.setData({ apiData }); + }, + + onLoad(options) { + console.log('onLoad:=====query:', options); + this.setData({ + title: options.title, + }); + }, + + switchTab() { + this.resetApiData(); + xhs.switchTab({ + url: '/page/API/index?sdsdsd=123', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, + + reLaunch() { + xhs.reLaunch({ + url: '/page/component/index?fdgsd=12323', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, + + navigateBack() { + xhs.navigateBack({ + delta: 2, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, + + navigateTo() { + xhs.navigateTo({ + url: 'page/component/pages/navigator/navigate?navi=123', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, + + redirectTo() { + xhs.redirectTo({ + url: 'page/component/pages/navigator/navigate?navi=123', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + }, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/navigator/navigate.json b/xhs-mini-demos/api-case/navigator/navigate.json new file mode 100644 index 0000000..814ddea --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigate.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "跳转页", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/navigator/navigate.xhsml b/xhs-mini-demos/api-case/navigator/navigate.xhsml new file mode 100644 index 0000000..3e8020e --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigate.xhsml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/navigator/navigator.css b/xhs-mini-demos/api-case/navigator/navigator.css new file mode 100644 index 0000000..ad2e676 --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigator.css @@ -0,0 +1,5 @@ + + +._dflex navigator button { + margin: 10px 0; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/navigator/navigator.js b/xhs-mini-demos/api-case/navigator/navigator.js new file mode 100644 index 0000000..8edf9e3 --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigator.js @@ -0,0 +1,172 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + console.log('------', content); + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + navigateTo() { + xhs.navigateTo({ + url: './navigator', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + navigateToError() { + xhs.navigateTo({ + url: './navigatorerror', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + navigateBack() { + xhs.navigateBack({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + navigateBack1() { + xhs.navigateBack({ + delta: -1, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + redirectTo() { + xhs.redirectTo({ + url: './navigator', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + redirectToError() { + xhs.redirectTo({ + url: './navigatorxxxx', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + switchTab() { + xhs.switchTab({ + url: '/page/component/index', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + switchTabError() { + xhs.switchTab({ + url: '/page/component/indexerror', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + reLaunch() { + xhs.reLaunch({ + url: '/page/component/index', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + reLaunchError() { + xhs.reLaunch({ + url: '/page/component/indexerror', + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/navigator/navigator.json b/xhs-mini-demos/api-case/navigator/navigator.json new file mode 100644 index 0000000..750a4ba --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigator.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "页面导航api", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/navigator/navigator.xhsml b/xhs-mini-demos/api-case/navigator/navigator.xhsml new file mode 100644 index 0000000..20aa8ff --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/navigator.xhsml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/navigator/redirect.css b/xhs-mini-demos/api-case/navigator/redirect.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/navigator/redirect.js b/xhs-mini-demos/api-case/navigator/redirect.js new file mode 100644 index 0000000..ec9e7cf --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/redirect.js @@ -0,0 +1,15 @@ +Page({ + onShareAppMessage() { + return { + title: 'redirectPage', + path: 'page/component/pages/navigator/redirect', + }; + }, + + onLoad(options) { + console.log('onLoad:=====query:', options); + this.setData({ + title: options.title, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/navigator/redirect.json b/xhs-mini-demos/api-case/navigator/redirect.json new file mode 100644 index 0000000..48156ad --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/redirect.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "redirectPage" +} diff --git a/xhs-mini-demos/api-case/navigator/redirect.xhsml b/xhs-mini-demos/api-case/navigator/redirect.xhsml new file mode 100644 index 0000000..1c47b50 --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/redirect.xhsml @@ -0,0 +1,2 @@ + + diff --git a/xhs-mini-demos/api-case/navigator/templates.js b/xhs-mini-demos/api-case/navigator/templates.js new file mode 100644 index 0000000..5e778bc --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/templates.js @@ -0,0 +1,274 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + + page_data_5: "", + + page_data_6: false, + + page_data_7: false, + + page_data_8: false, + + page_data_9: "", + + page_data_10: "", + + page_data_11: false, + + page_data_12: false, + + page_data_13: false, + + page_data_14: "", + + page_data_15: "", + + page_data_16: false, + + page_data_17: false, + + page_data_18: false, + + page_data_19: "", + + page_data_20: "", + + page_data_21: false, + + page_data_22: false, + + page_data_23: false, + + page_data_24: "", + + page_data_25: false, + + page_data_26: false, + + page_data_27: false, + + page_data_28: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.navigateBack({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + delta: this.data.page_data_0, + }); + }, + + page_fun_3(e) { + this.setData("page_data_5", e.detail.value); + }, + + page_fun_2() { + this.setData({ + page_data_6: false, + page_data_7: false, + page_data_8: false, + }); + + xhs.navigateTo({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_6: true, + page_data_9: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_7: true, + page_data_9: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_8: true, + }); + }, + url: this.data.page_data_5, + }); + }, + + page_fun_5(e) { + this.setData("page_data_10", e.detail.value); + }, + + page_fun_4() { + this.setData({ + page_data_11: false, + page_data_12: false, + page_data_13: false, + }); + + xhs.reLaunch({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_11: true, + page_data_14: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_12: true, + page_data_14: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_13: true, + }); + }, + url: this.data.page_data_10, + }); + }, + + page_fun_7(e) { + this.setData("page_data_15", e.detail.value); + }, + + page_fun_6() { + this.setData({ + page_data_16: false, + page_data_17: false, + page_data_18: false, + }); + + xhs.redirectTo({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_16: true, + page_data_19: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_17: true, + page_data_19: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_18: true, + }); + }, + url: this.data.page_data_15, + }); + }, + + page_fun_9(e) { + this.setData("page_data_20", e.detail.value); + }, + + page_fun_8() { + this.setData({ + page_data_21: false, + page_data_22: false, + page_data_23: false, + }); + + xhs.switchTab({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_21: true, + page_data_24: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_22: true, + page_data_24: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_23: true, + }); + }, + url: this.data.page_data_20, + }); + }, + + page_fun_10() { + this.setData({ + page_data_25: false, + page_data_26: false, + page_data_27: false, + }); + + xhs.exitMiniProgram({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_25: true, + page_data_28: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_26: true, + page_data_28: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_27: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/navigator/templates.xhsml b/xhs-mini-demos/api-case/navigator/templates.xhsml new file mode 100644 index 0000000..bd33252 --- /dev/null +++ b/xhs-mini-demos/api-case/navigator/templates.xhsml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/observer/observer.css b/xhs-mini-demos/api-case/observer/observer.css new file mode 100644 index 0000000..53336fa --- /dev/null +++ b/xhs-mini-demos/api-case/observer/observer.css @@ -0,0 +1,51 @@ +.wrap { + padding-top: 30rpx; +} + +.scroll-view { + height: 400rpx; + background: #fff; +} + +.scroll-area { + height: 1900rpx; + display: flex; + flex-direction: column; + align-items: center; + transition: .5s; +} + +.notice { + margin-top: 150rpx; +} + +.ball { + width: 100rpx; + height: 100rpx; + background: #38f; + border-radius: 50%; +} + +.ball2 { + width: 100rpx; + height: 100rpx; + background: #38f; + border-radius: 50%; + margin-top: 500rpx; +} + +.filling { + height: 400rpx; +} + +.message { + margin: 50rpx 0; + width: 100%; + display: flex; + justify-content: center; +} + +.message text { + font-size: 40rpx; + font-family: -apple-system-font, Helvetica Neue,Helvetica,sans-serif; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/observer/observer.js b/xhs-mini-demos/api-case/observer/observer.js new file mode 100644 index 0000000..fc021d7 --- /dev/null +++ b/xhs-mini-demos/api-case/observer/observer.js @@ -0,0 +1,44 @@ + +Page({ + data: { + appear: false, + appear2: false + }, + onReady() { + this.intersectionObserver = xhs.createIntersectionObserver(this); + // 监测 scroll-view 可视区域和小球元素节点的相交情况 + console.log('swan.createIntersectionObserve的可选值', this.intersectionObserver._options); + this.intersectionObserver + .relativeTo('.scroll-view1') + .observe('.ball', res => { + console.log('observe', res); + // boundingClientRect: 目标边界,这里指小球的位置情况,这个位置是相对于整个页面的,不是相对于参照元素的 scroll-view 的 + // dataset: 观察对象携带的数据。 + // id: 观察对象的 id,它与上面的 dataset 多使用于一次观察多个对象的场景,用于区分不同的对象。 + // intersectionRatio: 相交比例,为 0 时说明两者不相交。 + // intersectionRect: 相交区域,height 为 0 时说明此时没有相交。 + // relativeRect: 参照区域的边界,作为参考物,它的值一般是不会变的。可以对比它于开始相交时一直没变,因为它就是一个 scroll-view 的组件在页面上呈现出的位置信息。 + // time: 监测到两者相交时的时间戳 + this.setData('appear', res.intersectionRatio > 0); + }); + + this.intersectionObserver2 = xhs.createIntersectionObserver(this, { + selectAll: true + }); + this.intersectionObserver2 + .relativeTo('.scroll-view2') + .observe('.ball1, .ball2', res => { + console.log('observe2', res); + this.setData('appear2', res.intersectionRatio > 0); + }); + }, + onUnload() { + this.intersectionObserver && this.intersectionObserver.disconnect(); + this.intersectionObserver2 && this.intersectionObserver2.disconnect(); + + } +}); + + + + diff --git a/xhs-mini-demos/api-case/observer/observer.json b/xhs-mini-demos/api-case/observer/observer.json new file mode 100644 index 0000000..2dc3c35 --- /dev/null +++ b/xhs-mini-demos/api-case/observer/observer.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "监听节点", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/observer/observer.xhsml b/xhs-mini-demos/api-case/observer/observer.xhsml new file mode 100644 index 0000000..86a01cd --- /dev/null +++ b/xhs-mini-demos/api-case/observer/observer.xhsml @@ -0,0 +1,33 @@ + + + + 小球出现 + 小球消失 + + + + 向下滚动让小球出现 + + + + + + + + + 小球出现 + 小球消失 + + + + 向下滚动让小球出现 + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.css b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.css new file mode 100644 index 0000000..75bd3fd --- /dev/null +++ b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.css @@ -0,0 +1,7 @@ +.page-body-info { + height: 100px; +} +.page-body-text-network-type { + font-size: 40px; + font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif; +} diff --git a/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.js b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.js new file mode 100644 index 0000000..b46eca0 --- /dev/null +++ b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.js @@ -0,0 +1,34 @@ +Page({ + onShareAppMessage() { + return { + title: '监听手机网络变化', + path: 'packageAPI/pages/on-network-status-change/on-network-status-change', + }; + }, + + data: { + isConnected: false, + }, + + onLoad() { + const that = this; + xhs.onNetworkStatusChange(res => { + console.log('res----------', res); + that.setData({ + isConnected: res.isConnected, + networkType: res.networkType, + }); + }); + }, + onShow() { + const that = this; + xhs.getNetworkType({ + success(res) { + that.setData({ + isConnected: res.networkType !== 'none', + networkType: res.networkType, + }); + }, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.json b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.json new file mode 100644 index 0000000..0331701 --- /dev/null +++ b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "监听手机网络变化" +} diff --git a/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.xhsml b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.xhsml new file mode 100644 index 0000000..e7251af --- /dev/null +++ b/xhs-mini-demos/api-case/on-network-status-change/on-network-status-change.xhsml @@ -0,0 +1,15 @@ + + + + + 网络状态 + + 没有网络连接 + + + {{networkType}} + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/performance/performance.css b/xhs-mini-demos/api-case/performance/performance.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/performance/performance.js b/xhs-mini-demos/api-case/performance/performance.js new file mode 100644 index 0000000..4a87ec4 --- /dev/null +++ b/xhs-mini-demos/api-case/performance/performance.js @@ -0,0 +1,50 @@ +let performance; + +Page({ + data: { + entriesText: '', + entriesByName: '', + nameValue: '' + }, + + onLoad() { + performance = xhs.getPerformance(); + const observer = performance.createObserver((entryList) => { + console.log('entryList', entryList.getEntries()); + this.setData('entriesText', JSON.stringify(entryList.getEntries())); + console.log('allentryList', performance.getEntries()); + }); + observer.observe({ type: 'paint' }); + console.log('observer', observer); + this.observer = observer; + }, + + onReady() { + console.log('onReady', Date.now()); + }, + + onHide() { + this.observer.disconnect(); + }, + + onUnload() { + console.log('disconnect'); + this.observer.disconnect(); + }, + + + getEntries() { + const entries = performance?.getEntries(); + console.log('entries', entries); + this.setData('entriesText', JSON.stringify(entries)); + }, + + getEntriesByName() { + const entries = performance?.getEntriesByName(this.data.nameValue); + this.setData('entriesByName', JSON.stringify(entries)); + }, + + onNameInput(e) { + this.setData('nameValue', e.detail.value); + } +}); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/performance/performance.json b/xhs-mini-demos/api-case/performance/performance.json new file mode 100644 index 0000000..8c4238a --- /dev/null +++ b/xhs-mini-demos/api-case/performance/performance.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "小程序性能监测", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/performance/performance.xhsml b/xhs-mini-demos/api-case/performance/performance.xhsml new file mode 100644 index 0000000..d8f0867 --- /dev/null +++ b/xhs-mini-demos/api-case/performance/performance.xhsml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/preview-image/preview-image.css b/xhs-mini-demos/api-case/preview-image/preview-image.css new file mode 100644 index 0000000..499769f --- /dev/null +++ b/xhs-mini-demos/api-case/preview-image/preview-image.css @@ -0,0 +1,3 @@ +.weui-label { + width: 5em; +} diff --git a/xhs-mini-demos/api-case/preview-image/preview-image.js b/xhs-mini-demos/api-case/preview-image/preview-image.js new file mode 100644 index 0000000..cc51a5c --- /dev/null +++ b/xhs-mini-demos/api-case/preview-image/preview-image.js @@ -0,0 +1,35 @@ +Page({ + onShareAppMessage() { + return { + title: 'previewImage', + path: 'packageAPI/pages/set-tab-bar-item/set-tab-bar-item', + }; + }, + + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false, + }, + }, + + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '', + }, + }); + }, + + updateApiData(type, content) { + const apiData = { ...this.data.apiData }; + apiData[type] = true; + apiData.content = content; + this.setData({ apiData }); + }, +}); diff --git a/xhs-mini-demos/api-case/preview-image/preview-image.json b/xhs-mini-demos/api-case/preview-image/preview-image.json new file mode 100644 index 0000000..6b4275c --- /dev/null +++ b/xhs-mini-demos/api-case/preview-image/preview-image.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "设置TabBar" +} diff --git a/xhs-mini-demos/api-case/preview-image/preview-image.xhsml b/xhs-mini-demos/api-case/preview-image/preview-image.xhsml new file mode 100644 index 0000000..999197f --- /dev/null +++ b/xhs-mini-demos/api-case/preview-image/preview-image.xhsml @@ -0,0 +1,9 @@ + +
+ + + + + +
+
\ No newline at end of file diff --git a/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.css b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.css new file mode 100644 index 0000000..f1caa8f --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.css @@ -0,0 +1,6 @@ +.page-body-info { + background-color: transparent; +} +.btn-area{ + margin-top: 150px; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.js b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.js new file mode 100644 index 0000000..51d8c8c --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.js @@ -0,0 +1,66 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '下拉刷新', + path: 'api-case/pull-down-refresh/pull-down-refresh' + }; + }, + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = JSON.stringify(content); + this.setData({ + apiData + }); + }, + startPullDownRefresh() { + this.resetApiData(); + xhs.startPullDownRefresh({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + stopPullDownRefresh() { + this.resetApiData(); + xhs.stopPullDownRefresh({ + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.json b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.json new file mode 100644 index 0000000..a467f58 --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.json @@ -0,0 +1,10 @@ +{ + "navigationBarTitleText": "下拉刷新", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.xhsml b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.xhsml new file mode 100644 index 0000000..1db5e7b --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/pull-down-refresh.xhsml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/pull-down-refresh/templates.js b/xhs-mini-demos/api-case/pull-down-refresh/templates.js new file mode 100644 index 0000000..98e5676 --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/templates.js @@ -0,0 +1,83 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: false, + + page_data_1: false, + + page_data_2: false, + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_0() { + this.setData({ + page_data_0: false, + page_data_1: false, + page_data_2: false, + }); + + xhs.startPullDownRefresh({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_0: true, + page_data_3: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_1: true, + page_data_3: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_2: true, + }); + }, + }); + }, + + page_fun_1() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + xhs.stopPullDownRefresh({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/pull-down-refresh/templates.xhsml b/xhs-mini-demos/api-case/pull-down-refresh/templates.xhsml new file mode 100644 index 0000000..3aeea7f --- /dev/null +++ b/xhs-mini-demos/api-case/pull-down-refresh/templates.xhsml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/query/query.css b/xhs-mini-demos/api-case/query/query.css new file mode 100644 index 0000000..c41b7fa --- /dev/null +++ b/xhs-mini-demos/api-case/query/query.css @@ -0,0 +1,59 @@ +.flex-container-x { + display: flex; + justify-content: space-around; +} + +.flex-container-y { + display: flex; + flex-direction: column; + align-items: center; +} + +.flex-item { + display: flex; + justify-content: center; + align-items: center; + width: 80px; + height: 100px; + color: white; +} + +.flex-container-y .flex-item { + width: 100px; + height: 80px; +} + +.demo-1 { + background-color: rgb(255, 36, 65); +} + +.demo-2 { + background-color: rgba(255, 36, 65, 0.7); +} + +.demo-3 { + background-color: rgba(255, 36, 65, 0.5); +} + + + + + +.flex-item-V{ + margin: 0 auto; + width: 150px; + height: 100px; +} +.new-hover-class{ + background: red; +} +.outer { + background:green; +} +.middle { + background:gray; +} +.inner { + background:yellow; +} + diff --git a/xhs-mini-demos/api-case/query/query.js b/xhs-mini-demos/api-case/query/query.js new file mode 100644 index 0000000..ed444c8 --- /dev/null +++ b/xhs-mini-demos/api-case/query/query.js @@ -0,0 +1,51 @@ +Page({ + onShareAppMessage() { + return { + title: 'query', + path: '/api-case/query/query', + }; + }, + + data: { + content: '', + content2: '', + content3: '' + }, + + + handleGetQuery() { + const _this = this; + const query = xhs.createSelectorQuery(); + query.select('#box').boundingClientRect(); + query.selectViewport().scrollOffset(); + query.exec(function(res){ + _this.setData({ + content: JSON.stringify(res) + }); + }); + }, + + handleGetQueryAll() { + const _this = this; + const query = xhs.createSelectorQuery(); + query.selectAll('.box').boundingClientRect(); + query.selectViewport().scrollOffset(); + query.exec(function(res){ + _this.setData({ + content2: JSON.stringify(res) + }); + }); + }, + + selectViewport() { + const _this = this; + xhs.createSelectorQuery() + .selectViewport() + .scrollOffset(res => { + _this.setData({ + content3: JSON.stringify(res) + }); + }).exec(); + } + +}); diff --git a/xhs-mini-demos/api-case/query/query.json b/xhs-mini-demos/api-case/query/query.json new file mode 100644 index 0000000..e0946c2 --- /dev/null +++ b/xhs-mini-demos/api-case/query/query.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "节点查询", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/query/query.xhsml b/xhs-mini-demos/api-case/query/query.xhsml new file mode 100644 index 0000000..5ad0f94 --- /dev/null +++ b/xhs-mini-demos/api-case/query/query.xhsml @@ -0,0 +1,58 @@ + + + + + + 结果:{{content}} + + + A + + + + + + + + + + + 结果:{{content2}} + + + A + B + + + + + + + + + + + 结果:{{content3}} + + + + + diff --git a/xhs-mini-demos/api-case/request-payment/request-payment.css b/xhs-mini-demos/api-case/request-payment/request-payment.css new file mode 100644 index 0000000..87cfc9e --- /dev/null +++ b/xhs-mini-demos/api-case/request-payment/request-payment.css @@ -0,0 +1,31 @@ +.page-section { + width: auto; + margin: 15px; + padding: 62px 15px; + background-color: var(--weui-BG-2); + text-align: center; + font-size: 14px; +} +.desc { + color: var(--weui-FG-1); +} +.price { + margin-top: 15px; + margin-bottom: 13px; + position: relative; + display: inline-block; + font-size: 39px; + line-height: 1; +} +.price:before { + content: '¥'; + position: absolute; + font-size: 20px; + top: 4px; + left: -20px; +} + +.input { + height: 40px; + padding: 10px; +} diff --git a/xhs-mini-demos/api-case/request-payment/request-payment.js b/xhs-mini-demos/api-case/request-payment/request-payment.js new file mode 100644 index 0000000..622b023 --- /dev/null +++ b/xhs-mini-demos/api-case/request-payment/request-payment.js @@ -0,0 +1,288 @@ +const APPID = require('../../project.config.json').appid; +const SIT_SECRET = 'c6409ad5e089e2ceba58571cb745a058'; +const BETA_SECRET = '24906284213ef241efa0b1f57abe56ca'; +// const PROD_SECRET = '24906284213ef241efa0b1f57abe56ca' +const PROD_SECRET = '18c4677d24791d7496639882999cf261'; + +const evnMap = { + sit: { + SECRET: SIT_SECRET + }, + beta: { + SECRET: BETA_SECRET + }, + prod: { + SECRET: PROD_SECRET + } +}; + +// const env = 'sit'; +const env = 'beta'; +// const env = 'prod'; +const APP_ID = APPID; +const SECRET = evnMap[env].SECRET; + + + +const map = { + sit: { + API_ACCESS_TOKEN: 'http://miniapp.sit.xiaohongshu.com/api/rmp/token', + API_SESSION: 'http://miniapp.sit.xiaohongshu.com/api/rmp/session', + + API_NEW_ORDER: 'http://logan.devops.xiaohongshu.com/proxy/xhs-demo/api/sns/matrix/rmp/demo/order', + API_STATUS: 'http://logan.devops.xiaohongshu.com/proxy/xhs-demo/api/sns/matrix/rmp/demo/order/status', + + STATIC_WX_URL: 'http://www.sit.xiaohongshu.com/miniapp/mid-page?fullscreen=true&disableDragBack=yes&disableBackForwardNavigationGestures=true&source=12345' + }, + beta: { + API_ACCESS_TOKEN: 'https://miniapp.beta.xiaohongshu.com/api/rmp/token', + API_SESSION: 'https://miniapp.beta.xiaohongshu.com/api/rmp/session', + + API_NEW_ORDER: 'https://edith.beta.xiaohongshu.com/api/sns/matrix/rmp/demo/order', + API_STATUS: 'https://edith.beta.xiaohongshu.com/api/sns/matrix/rmp/demo/order/status', + + STATIC_WX_URL: 'https://www.beta.xiaohongshu.com/miniapp/mid-page?fullscreen=true&disableDragBack=yes&disableBackForwardNavigationGestures=true&source=12345' + }, + prod: { + API_ACCESS_TOKEN: 'https://miniapp.xiaohongshu.com/api/rmp/token', + API_SESSION: 'https://miniapp.xiaohongshu.com/api/rmp/session', + + API_NEW_ORDER: 'https://edith.xiaohongshu.com/api/sns/matrix/rmp/demo/order', + API_STATUS: 'https://edith.xiaohongshu.com/api/sns/matrix/rmp/demo/order/status', + + STATIC_WX_URL: 'https://www.xiaohongshu.com/miniapp/mid-page?fullscreen=true&disableDragBack=yes&disableBackForwardNavigationGestures=true&source=12345' + }, +}; + +const API_ACCESS_TOKEN = map[env].API_ACCESS_TOKEN; +const API_NEW_ORDER = map[env].API_NEW_ORDER; +const API_STATUS = map[env].API_STATUS; +const API_SESSION = map[env].API_SESSION; + +const STATIC_WX_URL = map[env].STATIC_WX_URL; +const STATIC_ZFB_URL = STATIC_WX_URL; + +Page({ + onShareAppMessage() { + return { + title: '发起支付', + path: 'api-case/request-payment/request-payment', + }; + }, + + data: { + customPaytoken: '', + customOrderId: '', + customPayMethod: 'test', + customAppId: '627a424c3d56430001c675fd', + + payToken: '', + orderId: '', + payMethod: 'xhs', + ext: '', + wxUrl: '', + zfbUrl: '', + + access_token: '', + open_id: '', + is_pay: false + }, + + handlePayTokenChange(e){ + this.setData({ + customPaytoken: e.detail.value + }); + }, + + handleOrderIdChange(e){ + this.setData({ + customOrderId: e.detail.value + }); + }, + + handlePayMethodChange(e){ + this.setData({ + customPayMethod: e.detail.value + }); + }, + + handleAppIdChange(e){ + this.setData({ + customAppId: e.detail.value + }); + }, + + handleCustomPayment(){ + const orderInfo = { + payToken: this.data.customPaytoken, + orderId: this.data.customOrderId, + payMethod: this.data.customPayMethod, + appId: this.data.customAppId, + }; + xhs.requestGuaranteeOrderPayment({ + orderInfo, + success: res => { + this.setData({ + is_pay: true + }); + console.log('支付结果', res); + }, + fail: res => { + xhs.showToast({ + title: '支付失败', + icon: 'none' + }); + console.log('支付结果', res); + }, + complete: () => { + xhs.request({ + url: `${API_STATUS}?openId=${this.data.open_id}&status=2&orderId=${outOrderId}`, + method: 'post', + success(res) { + console.log('res', res); + }, + fail(res) { + console.log('res', res); + } + }); + } + }); + }, + + // 新增订单 + insertOrder(openId, access_token) { + const PATH = '/api-case/request-payment/request-payment'; + return new Promise((resolve, reject) => { + xhs.request({ + url: `${API_NEW_ORDER}?openId=${openId}&path=${encodeURIComponent(PATH)}`, + method: 'post', + success: resolve, + fail: reject, + }); + }); + }, + + onShow() { + if(this.data.is_pay) { + xhs.showToast({ + title: '支付成功', + icon: 'none' + }); + } + }, + + login(access_token) { + return new Promise((resolve, reject) => { + xhs.login({ + success: (res) => { + const code = res.code; + const API_SESSION_URL = `${API_SESSION}?appid=${APP_ID}&access_token=${access_token}&code=${code}`; + xhs.request({ + url: API_SESSION_URL, + method: 'get', + success: (res) => { + this.setData({ + open_id: res.data.data.openid + }); + resolve(res.data.data.openid); + } + }); + }, + fail: reject + }); + }); + + }, + + // 获取调用凭证 + getAccessToken() { + return new Promise((resolve, reject) => { + xhs.request({ + url: API_ACCESS_TOKEN, + method: 'post', + data: { + appid: APP_ID, + secret: SECRET + }, + success: resolve, + fail: reject, + }); + }); + }, + + async handlePayment(e) { + xhs.showToast({ + title: '唤起收银台中...', + icon: 'none' + }); + try { + const tokenValue = await this.getAccessToken(); + console.log(tokenValue); + const access_token = tokenValue.data.data.access_token; + const loginValue = await this.login(access_token); + console.log(loginValue); + const orderValue = await this.insertOrder(loginValue, access_token); + console.log(orderValue); + this.pay(orderValue.data); + } catch(err) { + xhs.showToast({ + title: '支付失败', + icon: 'none' + }); + console.log(err); + } + + }, + + pay(value) { + console.log('value', value); + const payToken = value.data.payToken; + const orderId = value.data.orderId; + const outOrderId = value.data.outOrderId; + + console.log('payToken', payToken); + console.log('xhsOrderId', orderId); + console.log('outOrderId', outOrderId); + + const wxUrl = STATIC_WX_URL + '&payUrl=wx'; + const zfbUrl = STATIC_ZFB_URL + '&payUrl=zfb'; + + xhs.requestOrderPayment({ + orderInfo: { + payToken: payToken, + orderId: orderId, + payMethod: 'third', + wxUrl: wxUrl, + zfbUrl: zfbUrl, + }, + success: res => { + // xhs.showToast({ + // title: '支付成功' + // }) + this.setData({ + is_pay: true + }); + console.log('支付结果', res); + }, + fail: res => { + xhs.showToast({ + title: '支付失败', + icon: 'none' + }); + console.log('支付结果', res); + }, + complete: () => { + xhs.request({ + url: `${API_STATUS}?openId=${this.data.open_id}&status=2&orderId=${outOrderId}`, + method: 'post', + success(res) { + console.log('res', res); + }, + fail(res) { + console.log('res', res); + } + }); + } + }); + } +}); diff --git a/xhs-mini-demos/api-case/request-payment/request-payment.json b/xhs-mini-demos/api-case/request-payment/request-payment.json new file mode 100644 index 0000000..8024ca6 --- /dev/null +++ b/xhs-mini-demos/api-case/request-payment/request-payment.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "发起支付", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index" + } +} diff --git a/xhs-mini-demos/api-case/request-payment/request-payment.xhsml b/xhs-mini-demos/api-case/request-payment/request-payment.xhsml new file mode 100644 index 0000000..d232166 --- /dev/null +++ b/xhs-mini-demos/api-case/request-payment/request-payment.xhsml @@ -0,0 +1,64 @@ + + + + + 输入payToken + + + + 输入orderId + + + + 输入payMethod + + + + 输入appId + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/request/request.css b/xhs-mini-demos/api-case/request/request.css new file mode 100644 index 0000000..dd83adc --- /dev/null +++ b/xhs-mini-demos/api-case/request/request.css @@ -0,0 +1,4 @@ +._dflex button { + margin: 10px 0; + background-color: red; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/request/request.js b/xhs-mini-demos/api-case/request/request.js new file mode 100644 index 0000000..a666123 --- /dev/null +++ b/xhs-mini-demos/api-case/request/request.js @@ -0,0 +1,155 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +const requestUrl = require('../../config').requestUrl; +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '网络请求', + path: 'api-case/request/request' + }; + }, + data: {}, + request(e) { + console.log(e); + const method = e.target.dataset.method; + xhs.request({ + url: requestUrl, + method: method, + data: { + noncestr: Date.now() + }, + success(res) { + xhs.showModal({ + title: `${method}请求成功`, + content: `${JSON.stringify(res)}` + }); + }, + fail(res) { + xhs.showToast({ + title: `${method}请求失败:${JSON.stringify(res)}` + }); + } + }); + }, + makeRequest() { + xhs.request({ + url: requestUrl, + method: 'get', + success(res) { + xhs.showModal({ + title: '请求成功', + content: `${JSON.stringify(res)}` + }); + }, + fail(res) { + xhs.showToast({ + title: `请求失败:${JSON.stringify(res)}` + }); + } + }); + }, + makeRequestOptions() { + xhs.request({ + url: requestUrl, + method: 'OPTIONS', + data: { + noncestr: Date.now() + } + }); + }, + makeRequestHead() { + xhs.request({ + url: requestUrl, + method: 'HEAD', + data: { + noncestr: Date.now() + } + }); + }, + makeRequestPut() { + xhs.request({ + url: requestUrl, + method: 'PUT', + data: { + noncestr: Date.now() + } + }); + }, + makeRequestDelete() { + xhs.request({ + url: requestUrl, + method: 'DELETE', + data: { + noncestr: Date.now() + } + }); + }, + makeRequestPostJSON() { + xhs.request({ + url: requestUrl, + method: 'POST', + header: { + 'content-type': 'application-json' + }, + data: { + noncestr: Date.now() + } + }); + }, + makeRequestPostFormData() { + xhs.request({ + url: requestUrl, + header: { + 'content-type': 'multipart/form-data' + }, + data: { + name: 123, + sex: 456 + } + }); + }, + makeRequestTimeout() { + xhs.request({ + url: requestUrl, + timeout: 2000, + data: { + noncestr: Date.now() + } + }); + }, + makeRequestRequestArrayBuffer() { + xhs.request({ + url: requestUrl, + method: 'POST', + data: new ArrayBuffer(8), + dataType: 'arraybuffer' + }); + }, + makeRequestResponseArrayBuffer() { + xhs.request({ + method: 'POST', + url: requestUrl, + responseType: 'arraybuffer', + data: '123', + success(e){ + console.log('request success', e); + }, + fail(e){ + console.log('request fail', e); + }, + }); + }, + makeRequestPostForm() { + xhs.request({ + url: requestUrl, + method: 'POST', + header: { + 'content-type': 'application/x-www-form-urlencoded' + }, + data: { + name: 1, + age: 2 + } + }); + } +}, __templateJs)); diff --git a/xhs-mini-demos/api-case/request/request.json b/xhs-mini-demos/api-case/request/request.json new file mode 100644 index 0000000..e062789 --- /dev/null +++ b/xhs-mini-demos/api-case/request/request.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "网络请求", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/request/request.xhsml b/xhs-mini-demos/api-case/request/request.xhsml new file mode 100644 index 0000000..ceb945a --- /dev/null +++ b/xhs-mini-demos/api-case/request/request.xhsml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/request/templates.js b/xhs-mini-demos/api-case/request/templates.js new file mode 100644 index 0000000..0ad155e --- /dev/null +++ b/xhs-mini-demos/api-case/request/templates.js @@ -0,0 +1,93 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: "", + + page_data_4: "", + + page_data_5: "", + + page_data_6: "", + + page_data_7: false, + + page_data_8: false, + + page_data_9: false, + + page_data_10: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_4(e) { + this.setData("page_data_3", e.detail.value); + }, + + page_fun_5(e) { + this.setData("page_data_4", e.detail.value); + }, + + page_fun_6(e) { + this.setData("page_data_5", e.detail.value); + }, + + page_fun_7(e) { + this.setData("page_data_6", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_7: false, + page_data_8: false, + page_data_9: false, + }); + + xhs.request({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_7: true, + page_data_10: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_8: true, + page_data_10: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_9: true, + }); + }, + url: this.data.page_data_0, + data: this.data.page_data_1, + header: this.data.page_data_2, + timeout: this.data.page_data_3, + method: this.data.page_data_4, + dataType: this.data.page_data_5, + responseType: this.data.page_data_6, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/request/templates.xhsml b/xhs-mini-demos/api-case/request/templates.xhsml new file mode 100644 index 0000000..ba14e59 --- /dev/null +++ b/xhs-mini-demos/api-case/request/templates.xhsml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/scan-code/scan-code.css b/xhs-mini-demos/api-case/scan-code/scan-code.css new file mode 100644 index 0000000..4822af5 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/scan-code.css @@ -0,0 +1,4 @@ +.weui-cell__bd { + min-height: 24px; + word-break: break-all; +} diff --git a/xhs-mini-demos/api-case/scan-code/scan-code.js b/xhs-mini-demos/api-case/scan-code/scan-code.js new file mode 100644 index 0000000..d3d70a8 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/scan-code.js @@ -0,0 +1,54 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '扫码', + path: 'packageAPI/pages/scan-code/scan-code' + }; + }, + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + }, + content: '' + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + scanCode() { + xhs.scanCode({ + success: res => { + this.setData({ + content: JSON.stringify(res) + }); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/scan-code/scan-code.json b/xhs-mini-demos/api-case/scan-code/scan-code.json new file mode 100644 index 0000000..d8eaa00 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/scan-code.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "扫码", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/scan-code/scan-code.xhsml b/xhs-mini-demos/api-case/scan-code/scan-code.xhsml new file mode 100644 index 0000000..4a688c7 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/scan-code.xhsml @@ -0,0 +1,12 @@ + + + + 扫码结果:{{content}} + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/scan-code/templates.js b/xhs-mini-demos/api-case/scan-code/templates.js new file mode 100644 index 0000000..dc5ec66 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/templates.js @@ -0,0 +1,58 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: false, + + page_data_3: false, + + page_data_4: false, + + page_data_5: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_2: false, + page_data_3: false, + page_data_4: false, + }); + + xhs.scanCode({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_2: true, + page_data_5: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_3: true, + page_data_5: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_4: true, + }); + }, + onlyFromCamera: this.data.page_data_0, + scanType: this.data.page_data_1, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/scan-code/templates.xhsml b/xhs-mini-demos/api-case/scan-code/templates.xhsml new file mode 100644 index 0000000..3e80cf4 --- /dev/null +++ b/xhs-mini-demos/api-case/scan-code/templates.xhsml @@ -0,0 +1,33 @@ + + + + + + + + + + 是否开启onlyFromCamera + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/screen-brightness/screen-brightness.css b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.css new file mode 100644 index 0000000..c0755f0 --- /dev/null +++ b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.css @@ -0,0 +1,8 @@ +.page-body-text-screen-brightness { + font-size: 40px; + font-family: -apple-system-font, Helvetica Neue,Helvetica,sans-serif; +} + +.page-section-gap { + padding: 15px; +} diff --git a/xhs-mini-demos/api-case/screen-brightness/screen-brightness.js b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.js new file mode 100644 index 0000000..0a53e3c --- /dev/null +++ b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.js @@ -0,0 +1,47 @@ +Page({ + onShareAppMessage() { + return { + title: '屏幕亮度', + path: 'packageAPI/pages/screen-brightness/screen-brightness', + }; + }, + + data: { + screenBrightness: 0, + }, + + onLoad() { + this._updateScreenBrightness(); + }, + + changeBrightness(e) { + const value = Number.parseFloat( + (e.detail.value).toFixed(1), + ); + this.setData({ + screenBrightness: Number.parseFloat( + e.detail.value.toFixed(1), + ), + }); + xhs.setScreenBrightness({ + value, + + }); + }, + + _updateScreenBrightness() { + xhs.getScreenBrightness({ + success: res => { + console.log(res); + this.setData({ + screenBrightness: Number.parseFloat( + res.value.toFixed(1), + ), + }); + }, + fail(err) { + console.error(err); + }, + }); + }, +}); diff --git a/xhs-mini-demos/api-case/screen-brightness/screen-brightness.json b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.json new file mode 100644 index 0000000..333713b --- /dev/null +++ b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "屏幕亮度" +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/screen-brightness/screen-brightness.xhsml b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.xhsml new file mode 100644 index 0000000..3ab2f26 --- /dev/null +++ b/xhs-mini-demos/api-case/screen-brightness/screen-brightness.xhsml @@ -0,0 +1,14 @@ + + + + 当前屏幕亮度 + {{screenBrightness}} + + + 设置屏幕亮度 + + + + + + diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.css b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.js b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.js new file mode 100644 index 0000000..dcff2ca --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.js @@ -0,0 +1,86 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '设置页面颜色', + path: 'packageAPI/pages/set-navigation-bar-title/set-navigation-bar-color' + }; + }, + data: { + frontColor: '#000000', + backgroundColor: '#00ff00', + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + common(options) { + this.resetApiData(); + xhs.setNavigationBarColor({ + ...options, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + handleFrontColor(e) { + this.setData({ + frontColor: e.detail.value || '' + }); + }, + handleBackgroundColor(e) { + this.setData({ + backgroundColor: e.detail.value || '' + }); + }, + setNavigationBarColor1() { + this.common({ + frontColor: this.data.frontColor, + backgroundColor: this.data.backgroundColor + }); + }, + setNavigationBarColor3() { + this.common({ + frontColor: this.data.frontColor, + backgroundColor: this.data.backgroundColor, + animation: { + duration: 2000, + timingFunc: 'linear' + } + }); + }, + fail() { + this.common({ + frontColor: 123 + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.json b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.json new file mode 100644 index 0000000..ba9f06a --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "设置导航栏颜色", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.xhsml b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.xhsml new file mode 100644 index 0000000..9dca663 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/set-navigation-bar-color.xhsml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/templates.js b/xhs-mini-demos/api-case/set-navigation-bar-color/templates.js new file mode 100644 index 0000000..6c9db0e --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/templates.js @@ -0,0 +1,65 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: false, + + page_data_4: false, + + page_data_5: false, + + page_data_6: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_3: false, + page_data_4: false, + page_data_5: false, + }); + + xhs.setNavigationBarColor({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_3: true, + page_data_6: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_4: true, + page_data_6: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_5: true, + }); + }, + frontColor: this.data.page_data_0, + backgroundColor: this.data.page_data_1, + animation: this.data.page_data_2, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/set-navigation-bar-color/templates.xhsml b/xhs-mini-demos/api-case/set-navigation-bar-color/templates.xhsml new file mode 100644 index 0000000..49ebf79 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-color/templates.xhsml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.css b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.js b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.js new file mode 100644 index 0000000..0106415 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.js @@ -0,0 +1,58 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '设置页面标题', + path: 'packageAPI/pages/set-navigation-bar-title/set-navigation-bar-title' + }; + }, + data: { + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + handleTitle(e) { + this.setData({ + title: e.detail.value + }); + }, + setNaivgationBarTitle() { + xhs.setNavigationBarTitle({ + title: this.data.title, + success: res => { + this.updateApiData('success', res); + }, + fail: res => { + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + return false; + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.json b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.json new file mode 100644 index 0000000..acf3e93 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "设置页面标题", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.xhsml b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.xhsml new file mode 100644 index 0000000..eb7b1f6 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/set-navigation-bar-title.xhsml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/templates.js b/xhs-mini-demos/api-case/set-navigation-bar-title/templates.js new file mode 100644 index 0000000..035367f --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/templates.js @@ -0,0 +1,111 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: false, + + page_data_4: false, + + page_data_5: false, + + page_data_6: "", + + page_data_7: "", + + page_data_8: false, + + page_data_9: false, + + page_data_10: false, + + page_data_11: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_3: false, + page_data_4: false, + page_data_5: false, + }); + + xhs.setNavigationBarColor({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_3: true, + page_data_6: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_4: true, + page_data_6: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_5: true, + }); + }, + frontColor: this.data.page_data_0, + backgroundColor: this.data.page_data_1, + animation: this.data.page_data_2, + }); + }, + + page_fun_5(e) { + this.setData("page_data_7", e.detail.value); + }, + + page_fun_4() { + this.setData({ + page_data_8: false, + page_data_9: false, + page_data_10: false, + }); + + xhs.setNavigationBarTitle({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_8: true, + page_data_11: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_9: true, + page_data_11: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_10: true, + }); + }, + title: this.data.page_data_7, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/set-navigation-bar-title/templates.xhsml b/xhs-mini-demos/api-case/set-navigation-bar-title/templates.xhsml new file mode 100644 index 0000000..d8acce8 --- /dev/null +++ b/xhs-mini-demos/api-case/set-navigation-bar-title/templates.xhsml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.css b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.css @@ -0,0 +1 @@ + diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.js b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.js new file mode 100644 index 0000000..210bf30 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.js @@ -0,0 +1,87 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '设置TabBarItem', + path: 'packageAPI/pages/set-tab-bar-item/set-tab-bar-item' + }; + }, + data: { + index: 0, + text: 'newText', + iconPath: 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/baobaozhidao@2x-af409f9dbe.png', + selectedIconPath: 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/yinyue@2x-c18adacacb.png' + }, + handleIndex(e) { + this.setData({ + index: e.detail.value + }); + }, + handleText(e) { + this.setData({ + text: e.detail.value + }); + }, + handleIconPath(e) { + this.setData({ + iconPath: e.detail.value + }); + }, + handleSelectIconPath(e) { + this.setData({ + selectedIconPath: e.detail.value + }); + }, + setTabBarItem() { + xhs.navigateBack({ + success: () => { + xhs.setTabBarItem({ + index: this.data.index, + text: this.data.text, + iconPath: this.data.iconPath, + selectedIconPath: this.data.selectedIconPath, + success: res => { + xhs.showToast({ + title: '设置成功', + icon: 'node' + }); + }, + fail: res => {} + }); + } + }); + }, + showTabBar() { + xhs.navigateBack({ + success: () => { + xhs.showTabBar({ + animation: true, + success: res => {}, + fail: res => {} + }); + } + }); + }, + hideTabBar() { + xhs.navigateBack({ + success: () => { + xhs.hideTabBar({ + success: res => {}, + fail: res => {} + }); + } + }); + }, + hideTabBarAnimate() { + xhs.navigateBack({ + success: () => { + xhs.hideTabBar({ + animation: true, + success: res => {}, + fail: res => {} + }); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.json b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.json new file mode 100644 index 0000000..f622f70 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "设置TabBar", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.xhsml b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.xhsml new file mode 100644 index 0000000..6d04783 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/set-tab-bar-item.xhsml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/templates.js b/xhs-mini-demos/api-case/set-tab-bar-item/templates.js new file mode 100644 index 0000000..0c5339a --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/templates.js @@ -0,0 +1,72 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_4(e) { + this.setData("page_data_3", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + xhs.setTabBarItem({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, + index: this.data.page_data_0, + text: this.data.page_data_1, + iconPath: this.data.page_data_2, + selectedIconPath: this.data.page_data_3, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/set-tab-bar-item/templates.xhsml b/xhs-mini-demos/api-case/set-tab-bar-item/templates.xhsml new file mode 100644 index 0000000..8261f84 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-item/templates.xhsml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.css b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.js b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.js new file mode 100644 index 0000000..325f5f2 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.js @@ -0,0 +1,73 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '设置TabBarStyle', + path: 'packageAPI/pages/set-tab-bar-style/set-tab-bar-style' + }; + }, + data: { + color: '#0000ff', + selectedColor: '#ff0000', + backgroundColor: '#00ff00', + borderStyle: 'black' + }, + handleColor(e) { + this.setData({ + color: e.detail.value + }); + }, + handleSelectColor(e) { + this.setData({ + selectedColor: e.detail.value + }); + }, + handleBackgroundColor(e) { + this.setData({ + backgroundColor: e.detail.value + }); + }, + handleBorderStyle(e) { + this.setData({ + borderStyle: e.detail.value + }); + }, + setTabBarStyle() { + xhs.navigateBack({ + success: () => { + xhs.setTabBarStyle({ + color: this.data.color, + selectedColor: this.data.selectedColor, + backgroundColor: this.data.backgroundColor, + borderStyle: this.data.borderStyle, + success: res => { + xhs.showToast({ + title: '设置成功', + icon: 'none' + }); + }, + fail: res => {} + }); + } + }); + }, + reBack() { + xhs.navigateBack({ + success: () => { + xhs.setTabBarStyle({ + color: 'rgba(51, 51, 51, 0.4)', + selectedColor: '#ff0000', + backgroundColor: '#ffffff', + success: res => { + xhs.showToast({ + title: '设置成功', + icon: 'none' + }); + }, + fail: res => {} + }); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.json b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.json new file mode 100644 index 0000000..2253716 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "设置TabBarStyle", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.xhsml b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.xhsml new file mode 100644 index 0000000..ddbc077 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-style/set-tab-bar-style.xhsml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/templates.js b/xhs-mini-demos/api-case/set-tab-bar-style/templates.js new file mode 100644 index 0000000..82d27cc --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-style/templates.js @@ -0,0 +1,72 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: "", + + page_data_4: false, + + page_data_5: false, + + page_data_6: false, + + page_data_7: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_4(e) { + this.setData("page_data_3", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_4: false, + page_data_5: false, + page_data_6: false, + }); + + xhs.setTabBarStyle({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_4: true, + page_data_7: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_5: true, + page_data_7: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_6: true, + }); + }, + color: this.data.page_data_0, + selectedColor: this.data.page_data_1, + backgroundColor: this.data.page_data_2, + borderStyle: this.data.page_data_3, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/set-tab-bar-style/templates.xhsml b/xhs-mini-demos/api-case/set-tab-bar-style/templates.xhsml new file mode 100644 index 0000000..d406b47 --- /dev/null +++ b/xhs-mini-demos/api-case/set-tab-bar-style/templates.xhsml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/setting/setting.css b/xhs-mini-demos/api-case/setting/setting.css new file mode 100644 index 0000000..3df9677 --- /dev/null +++ b/xhs-mini-demos/api-case/setting/setting.css @@ -0,0 +1,12 @@ +._dflex button { + margin: 10px 0; + background-color: red; + color: white; +} + +.setting-title { + font-size: 12px; + padding-bottom: 16px; + color: #333333; + text-align: center; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/setting/setting.js b/xhs-mini-demos/api-case/setting/setting.js new file mode 100644 index 0000000..4706656 --- /dev/null +++ b/xhs-mini-demos/api-case/setting/setting.js @@ -0,0 +1,111 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +const app = getApp(); +const platform = app.globalData.platform; +const isAuthorize = value => { + if (platform === 'ios') { + return value; + } else { + return value === 1; + } +}; +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '授权设置', + path: '/api-case/setting/setting' + }; + }, + data: { + config: '' + }, + handleGetSetting(scope) { + const showToast = text => { + xhs.showToast({ + title: text, + icon: 'none' + }); + }; + xhs.getSetting({ + success(res) { + console.log(res); + if (!isAuthorize(res.authSetting[scope])) { + xhs.authorize({ + scope, + success(res) { + xhs.showModal({ + title: '授权成功', + content: JSON.stringify(res) + }); + console.log(res); + }, + fail(res) { + showToast('授权失败'); + console.log(res); + } + }); + return; + } + showToast('已授权'); + } + }); + }, + handleAuthorize(e) { + const scope = e.target.dataset.scope; + this.handleGetSetting(scope); + }, + getSetting() { + xhs.getSetting({ + success: res => { + xhs.showModal({ + title: '设置信息获取成功', + content: JSON.stringify(res.authSetting) + }); + } + }); + }, + openSetting() { + xhs.openSetting({ + success: res => { + console.log(res); + } + }); + }, + handleUserInfo(e) { + if (e.detail.userInfo) { + xhs.showModal({ + title: '获取 userInfo 成功', + content: JSON.stringify(e.detail) + }); + } else { + xhs.showModal({ + title: '获取 userInfo 失败', + content: JSON.stringify(e.detail.errMsg) + }); + } + }, + getPhoneNumber(e) { + console.log(e); + if (e.detail.encryptedData) { + xhs.showToast({ + title: '获取成功', + icon: 'none' + }); + } else { + xhs.showModal({ + title: '授权失败,请先登陆', + content: e.detail.errMsg + }); + } + }, + login() { + xhs.login({ + success: res => { + console.log('loginSuccess', res); + }, + fail: res => { + console.log('loginFail', res); + } + }); + } +}, __templateJs)); diff --git a/xhs-mini-demos/api-case/setting/setting.json b/xhs-mini-demos/api-case/setting/setting.json new file mode 100644 index 0000000..4b94360 --- /dev/null +++ b/xhs-mini-demos/api-case/setting/setting.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "授权", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/setting/setting.xhsml b/xhs-mini-demos/api-case/setting/setting.xhsml new file mode 100644 index 0000000..0b6bfe6 --- /dev/null +++ b/xhs-mini-demos/api-case/setting/setting.xhsml @@ -0,0 +1,117 @@ + + + + + + 点击下方按钮进行登录 + + + + + + + + + 点击下方按钮进行getUserInfo + + + + + + + + + 点击下方按钮进行授权 + + + + + + + + + 点击下方按钮进行授权 + + + + + + + + + 点击下方按钮进行授权 + + + + + + + + + 点击下方按钮进行授权 + + + + + + + + + 点击下方按钮进行授权 + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/setting/templates.js b/xhs-mini-demos/api-case/setting/templates.js new file mode 100644 index 0000000..f3c39a8 --- /dev/null +++ b/xhs-mini-demos/api-case/setting/templates.js @@ -0,0 +1,129 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: false, + + page_data_2: false, + + page_data_3: false, + + page_data_4: "", + + page_data_5: false, + + page_data_6: false, + + page_data_7: false, + + page_data_8: "", + + page_data_9: false, + + page_data_10: false, + + page_data_11: false, + + page_data_12: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_1: false, + page_data_2: false, + page_data_3: false, + }); + + xhs.authorize({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_1: true, + page_data_4: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_2: true, + page_data_4: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_3: true, + }); + }, + scope: this.data.page_data_0, + }); + }, + + page_fun_2() { + this.setData({ + page_data_5: false, + page_data_6: false, + page_data_7: false, + }); + + xhs.getSetting({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_5: true, + page_data_8: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_6: true, + page_data_8: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_7: true, + }); + }, + }); + }, + + page_fun_3() { + this.setData({ + page_data_9: false, + page_data_10: false, + page_data_11: false, + }); + + xhs.openSetting({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_9: true, + page_data_12: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_10: true, + page_data_12: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_11: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/setting/templates.xhsml b/xhs-mini-demos/api-case/setting/templates.xhsml new file mode 100644 index 0000000..ec5835c --- /dev/null +++ b/xhs-mini-demos/api-case/setting/templates.xhsml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/share/share.css b/xhs-mini-demos/api-case/share/share.css new file mode 100644 index 0000000..779360d --- /dev/null +++ b/xhs-mini-demos/api-case/share/share.css @@ -0,0 +1,7 @@ + + +._dflex button { + margin: 10px 0; + color: white; + background-color: red; +} \ No newline at end of file diff --git a/xhs-mini-demos/api-case/share/share.js b/xhs-mini-demos/api-case/share/share.js new file mode 100644 index 0000000..df97bbe --- /dev/null +++ b/xhs-mini-demos/api-case/share/share.js @@ -0,0 +1,109 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + if (this.data.promise) { + const promise = Promise.resolve({ + title: '自定义转发标题Promise', + desc: '自定义转发描述Promise', + path: '/api-case/share/share' + }); + return { + ...this.data.shareData, + promise + }; + } + return { + ...this.data.shareData + }; + }, + data: { + shareData: { + title: '自定义转发标题', + desc: '自定义转发描述', + path: '/api-case/share/share', + imageUrl: 'https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/baiduyun@2x-e0be79e69e.png' + }, + apiData: { + content: '', + success: false, + fail: false, + complete: false + }, + promise: false + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + showShareMenu() { + this.resetApiData(); + xhs.showShareMenu({ + success: res => { + console.log("%c Line:59 🥝 showShareMenu res", "color:#ffdd4d", res); + this.updateApiData('success', res); + }, + fail: res => { + console.log("%c Line:59 🥝 showShareMenu err", "color:#ffdd4d", res); + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + hideShareMenu() { + this.resetApiData(); + xhs.hideShareMenu({ + shareTypes: 'normal', + success: res => { + console.log("%c Line:75 🍡 hideShareMenu res", "color:#93c0a4", res); + this.updateApiData('success', res); + }, + fail: res => { + console.log("%c Line:79 🍩 hideShareMenu err", "color:#465975", res); + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + handleTitle(e) { + this.setData({ + shareData: { + ...this.data.shareData, + title: e.detail.value + } + }); + }, + handleImageUrl(e) { + this.setData({ + shareData: { + ...this.data.shareData, + imageUrl: e.detail.value + } + }); + }, + handlePromise(e) { + this.setData({ + promise: e.detail.value + }); + } +}, __templateJs)); diff --git a/xhs-mini-demos/api-case/share/share.json b/xhs-mini-demos/api-case/share/share.json new file mode 100644 index 0000000..3327200 --- /dev/null +++ b/xhs-mini-demos/api-case/share/share.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "转发", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/share/share.xhsml b/xhs-mini-demos/api-case/share/share.xhsml new file mode 100644 index 0000000..a3c5bbc --- /dev/null +++ b/xhs-mini-demos/api-case/share/share.xhsml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/share/templates.js b/xhs-mini-demos/api-case/share/templates.js new file mode 100644 index 0000000..c2f67a8 --- /dev/null +++ b/xhs-mini-demos/api-case/share/templates.js @@ -0,0 +1,143 @@ +/** 以下内容为自动生成,请勿手动修改 */ + +module.exports = { + data: { + page_data_0: "", + + page_data_1: "", + + page_data_2: "", + + page_data_3: false, + + page_data_4: false, + + page_data_5: false, + + page_data_6: "", + + page_data_7: false, + + page_data_8: false, + + page_data_9: false, + + page_data_10: "", + + page_data_11: false, + + page_data_12: false, + + page_data_13: false, + + page_data_14: "", + }, + + page_fun_1(e) { + this.setData("page_data_0", e.detail.value); + }, + + page_fun_2(e) { + this.setData("page_data_1", e.detail.value); + }, + + page_fun_3(e) { + this.setData("page_data_2", e.detail.value); + }, + + page_fun_0() { + this.setData({ + page_data_3: false, + page_data_4: false, + page_data_5: false, + }); + + xhs.share({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_3: true, + page_data_6: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_4: true, + page_data_6: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_5: true, + }); + }, + title: this.data.page_data_0, + path: this.data.page_data_1, + imageUrl: this.data.page_data_2, + }); + }, + + page_fun_4() { + this.setData({ + page_data_7: false, + page_data_8: false, + page_data_9: false, + }); + + xhs.showShareMenu({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_7: true, + page_data_10: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_8: true, + page_data_10: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_9: true, + }); + }, + }); + }, + + page_fun_5() { + this.setData({ + page_data_11: false, + page_data_12: false, + page_data_13: false, + }); + + xhs.hideShareMenu({ + success: (res) => { + console.log("success", res); + this.setData({ + page_data_11: true, + page_data_14: JSON.stringify(res), + }); + }, + fail: (res) => { + console.log("fail", res); + this.setData({ + page_data_12: true, + page_data_14: JSON.stringify(res), + }); + }, + complete: (res) => { + console.log("complete", res); + this.setData({ + page_data_13: true, + }); + }, + }); + }, +}; diff --git a/xhs-mini-demos/api-case/share/templates.xhsml b/xhs-mini-demos/api-case/share/templates.xhsml new file mode 100644 index 0000000..efbe691 --- /dev/null +++ b/xhs-mini-demos/api-case/share/templates.xhsml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xhs-mini-demos/api-case/storage-async/status.xhsml b/xhs-mini-demos/api-case/storage-async/status.xhsml new file mode 100644 index 0000000..3b1bf4f --- /dev/null +++ b/xhs-mini-demos/api-case/storage-async/status.xhsml @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/xhs-mini-demos/api-case/storage-async/storage-async.css b/xhs-mini-demos/api-case/storage-async/storage-async.css new file mode 100644 index 0000000..e69de29 diff --git a/xhs-mini-demos/api-case/storage-async/storage-async.js b/xhs-mini-demos/api-case/storage-async/storage-async.js new file mode 100644 index 0000000..353e2ff --- /dev/null +++ b/xhs-mini-demos/api-case/storage-async/storage-async.js @@ -0,0 +1,317 @@ +const __templateJs = require("./templates.js"); +const __mergePageOptions = require("../../util/mergePageOptions.js"); +Page(__mergePageOptions({ + onShareAppMessage() { + return { + title: '异步存储', + path: 'packageAPI/pages/storageAsync/storage' + }; + }, + resetApiData() { + this.setData({ + apiData: { + success: false, + fail: false, + complete: false, + content: '' + } + }); + }, + updateApiData(type, content) { + const apiData = { + ...this.data.apiData + }; + apiData[type] = true; + apiData.content = content; + this.setData({ + apiData + }); + }, + data: { + key: '', + data: '', + title: '', + content: '', + apiData: { + content: '', + success: false, + fail: false, + complete: false + } + }, + keyChange(e) { + this.setData({ + key: e.detail.value + }); + }, + dataChange(e) { + this.setData({ + data: e.detail.value + }); + }, + getStorage() { + this.resetApiData(); + const { + key + } = this.data; + let data; + this.setData({ + title: '读取数中...', + content: '' + }); + if (key.length === 0) { + this.setData({ + key, + data + }); + this.setData({ + title: '读取数据失败', + content: 'key 不能为空' + }); + } else { + xhs.getStorage({ + key, + success: res => { + this.updateApiData('success', res); + if (typeof data === 'object') data = JSON.stringify(data); + this.setData({ + key, + data: res.data + }); + this.setData({ + title: '读取数据成功', + content: `key为: ${key} data 数据为: ${res.data}` + }); + }, + fail: res => { + this.setData({ + key, + data: data + }); + this.setData({ + title: '读取数据失败', + content: '找不到 key 对应的数据' + }); + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } + }, + setStorage() { + this.resetApiData(); + const { + key, + data + } = this.data; + this.setData({ + title: '存储中...', + content: '' + }); + if (key.length === 0) { + this.setData({ + key, + data + }); + this.setData({ + title: '保存数据失败', + content: 'key 不能为空' + }); + } else { + xhs.setStorage({ + key, + data, + success: res => { + this.setData({ + key, + data + }); + this.setData({ + title: '存储数据成功', + content: `key: ${key}, data: ${data}` + }); + this.updateApiData('success', res); + }, + fail: res => { + this.setData({ + key, + data + }); + this.setData({ + title: '存储数据失败', + content: '' + }); + this.updateApiData('fail', res); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } + }, + setStorageObject() { + this.resetApiData(); + const { + key, + data + } = this.data; + this.setData({ + title: '存储中...', + content: '' + }); + if (key.length === 0) { + this.setData({ + key, + data + }); + this.setData({ + title: '保存数据失败', + content: 'key 不能为空' + }); + } else { + xhs.setStorage({ + key, + data, + success: res => { + this.updateApiData('success', res); + this.setData({ + key, + data: { + age: 20 + } + }); + this.setData({ + title: '存储数据成功', + content: `key: ${key}, data: ${JSON.stringify({ + age: 20 + })}` + }); + }, + fail: res => { + this.updateApiData('fail', res); + this.setData({ + key, + data + }); + this.setData({ + title: '存储数据失败', + content: '' + }); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } + }, + clearStorageByKey() { + this.resetApiData(); + const key = this.data.key; + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: `key ${key} 清除中...`, + content: '' + }); + xhs.removeStorage({ + key, + success: res => { + this.updateApiData('success', res); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: `key ${key} 清除数据成功`, + content: '' + }); + }, + fail: res => { + this.updateApiData('fail', res); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: `key ${key} 清除数据失败`, + content: '' + }); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + getStorageInfo() { + this.resetApiData(); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: 'storageInfo 获取中...', + content: '' + }); + xhs.getStorageInfo({ + success: result => { + this.updateApiData('success', result); + this.setData({ + title: 'storageInfo获取成功', + content: `数据为: ${JSON.stringify(result)}` + }); + }, + fail: res => { + this.updateApiData('fail', res); + this.setData({ + title: 'storageInfo获取失败', + content: '' + }); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + }, + clearStorage() { + this.resetApiData(); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: '清除中...', + content: '' + }); + xhs.clearStorage({ + success: res => { + this.updateApiData('success', res); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: '清除数据成功', + content: '' + }); + }, + fail: res => { + this.updateApiData('fail', res); + this.setData({ + key: '', + data: '' + }); + this.setData({ + title: '清除数据失败', + content: '' + }); + }, + complete: res => { + this.updateApiData('complete', res); + } + }); + } +}, __templateJs)); \ No newline at end of file diff --git a/xhs-mini-demos/api-case/storage-async/storage-async.json b/xhs-mini-demos/api-case/storage-async/storage-async.json new file mode 100644 index 0000000..eed6012 --- /dev/null +++ b/xhs-mini-demos/api-case/storage-async/storage-async.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "异步存储", + "usingComponents": { + "showbox": "../../common/component/showbox/index", + "box": "../../common/component/container/index", + "api-status": "../../common/component/api-status/index" + } +} diff --git a/xhs-mini-demos/api-case/storage-async/storage-async.xhsml b/xhs-mini-demos/api-case/storage-async/storage-async.xhsml new file mode 100644 index 0000000..fd12aa3 --- /dev/null +++ b/xhs-mini-demos/api-case/storage-async/storage-async.xhsml @@ -0,0 +1,76 @@ + +