init
This commit is contained in:
19
xhs-mini-demos/api-case/storage-async/status.xhsml
Normal file
19
xhs-mini-demos/api-case/storage-async/status.xhsml
Normal file
@@ -0,0 +1,19 @@
|
||||
<template name="status">
|
||||
<view style="text-align:center">响应状态</view>
|
||||
<view style="display:flex;flex-direction:row;justify-content:space-around;overflow:scorll">
|
||||
<text style="color:{{apiData.success?'green':'red'}}">
|
||||
success
|
||||
</text>
|
||||
<text style="color:{{apiData.fail?'green':'red'}}">
|
||||
fail
|
||||
</text>
|
||||
<text style="color:{{apiData.complete?'green':'red'}}">
|
||||
complete
|
||||
</text>
|
||||
</view>
|
||||
<scroll-view scroll-y="{{true}}" style="width: 375px; height:100px">
|
||||
<text style="width:375px; white-space:break-spaces">
|
||||
{{apiData.content}}
|
||||
</text>
|
||||
</scroll-view>
|
||||
</template>
|
||||
317
xhs-mini-demos/api-case/storage-async/storage-async.js
Normal file
317
xhs-mini-demos/api-case/storage-async/storage-async.js
Normal file
@@ -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));
|
||||
8
xhs-mini-demos/api-case/storage-async/storage-async.json
Normal file
8
xhs-mini-demos/api-case/storage-async/storage-async.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "异步存储",
|
||||
"usingComponents": {
|
||||
"showbox": "../../common/component/showbox/index",
|
||||
"box": "../../common/component/container/index",
|
||||
"api-status": "../../common/component/api-status/index"
|
||||
}
|
||||
}
|
||||
76
xhs-mini-demos/api-case/storage-async/storage-async.xhsml
Normal file
76
xhs-mini-demos/api-case/storage-async/storage-async.xhsml
Normal file
@@ -0,0 +1,76 @@
|
||||
<view class="container">
|
||||
<template is="status" data="{{apiData}}" />
|
||||
<showbox title="异步数据存储">
|
||||
<box>
|
||||
<view style="padding: 5px 0;">
|
||||
<view style="text-align: center">{{ title }}</view>
|
||||
<view style="text-align: center" class="_text_wrap">{{ content }}</view>
|
||||
</view>
|
||||
<view class="_ui-space">
|
||||
<view class="_ui-input">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="请输入key"
|
||||
name="key"
|
||||
value="{{ key }}"
|
||||
bindinput="keyChange"
|
||||
/>
|
||||
</view>
|
||||
<view class="_ui-input">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="请输入value"
|
||||
name="data"
|
||||
value="{{ data }}"
|
||||
bindinput="dataChange"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="setStorage"
|
||||
>
|
||||
存储数据
|
||||
</button>
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="setStorageObject"
|
||||
>
|
||||
存储Object数据
|
||||
</button>
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="getStorage"
|
||||
>
|
||||
读取数据
|
||||
</button>
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="clearStorageByKey"
|
||||
>
|
||||
通过key清理数据
|
||||
</button>
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="getStorageInfo"
|
||||
>
|
||||
获取storage信息
|
||||
</button>
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="clearStorage"
|
||||
>
|
||||
清理数据
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
|
||||
<include src="templates.xhsml" />
|
||||
182
xhs-mini-demos/api-case/storage-async/templates.js
Normal file
182
xhs-mini-demos/api-case/storage-async/templates.js
Normal file
@@ -0,0 +1,182 @@
|
||||
/** 以下内容为自动生成,请勿手动修改 */
|
||||
|
||||
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: "",
|
||||
|
||||
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_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_0() {
|
||||
this.setData({
|
||||
page_data_2: false,
|
||||
page_data_3: false,
|
||||
page_data_4: false,
|
||||
});
|
||||
|
||||
xhs.setStorage({
|
||||
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,
|
||||
});
|
||||
},
|
||||
key: this.data.page_data_0,
|
||||
data: this.data.page_data_1,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_4(e) {
|
||||
this.setData("page_data_6", e.detail.value);
|
||||
},
|
||||
|
||||
page_fun_3() {
|
||||
this.setData({
|
||||
page_data_7: false,
|
||||
page_data_8: false,
|
||||
page_data_9: false,
|
||||
});
|
||||
|
||||
xhs.getStorage({
|
||||
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,
|
||||
});
|
||||
},
|
||||
key: this.data.page_data_6,
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_5() {
|
||||
this.setData({
|
||||
page_data_11: false,
|
||||
page_data_12: false,
|
||||
page_data_13: false,
|
||||
});
|
||||
|
||||
xhs.clearStorage({
|
||||
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,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
page_fun_6() {
|
||||
this.setData({
|
||||
page_data_15: false,
|
||||
page_data_16: false,
|
||||
page_data_17: false,
|
||||
});
|
||||
|
||||
xhs.getStorageInfo({
|
||||
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,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
99
xhs-mini-demos/api-case/storage-async/templates.xhsml
Normal file
99
xhs-mini-demos/api-case/storage-async/templates.xhsml
Normal file
@@ -0,0 +1,99 @@
|
||||
<!-- 以下内容为自动生成,请勿手动修改 -->
|
||||
|
||||
<view class="container">
|
||||
<showbox title="setStorage演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_2}}"
|
||||
complete="{{page_data_4}}"
|
||||
fail="{{page_data_3}}"
|
||||
text="{{page_data_5}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="key" type="text" bindinput="page_fun_1" />
|
||||
</view>
|
||||
|
||||
<view class="_ui-input">
|
||||
<input placeholder="data" type="text" bindinput="page_fun_2" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_0"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="getStorage演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_7}}"
|
||||
complete="{{page_data_9}}"
|
||||
fail="{{page_data_8}}"
|
||||
text="{{page_data_10}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<view class="_ui-input">
|
||||
<input placeholder="key" type="text" bindinput="page_fun_4" />
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_3"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="clearStorage演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_11}}"
|
||||
complete="{{page_data_13}}"
|
||||
fail="{{page_data_12}}"
|
||||
text="{{page_data_14}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_5"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
|
||||
<showbox title="getStorageInfo演示">
|
||||
<box>
|
||||
<api-status
|
||||
success="{{page_data_15}}"
|
||||
complete="{{page_data_17}}"
|
||||
fail="{{page_data_16}}"
|
||||
text="{{page_data_18}}"
|
||||
>
|
||||
</api-status>
|
||||
<view class="_ui-space _mt8">
|
||||
<button
|
||||
class="_ui-button"
|
||||
hover-class="_ui-button-hover"
|
||||
bindtap="page_fun_6"
|
||||
>
|
||||
触发
|
||||
</button>
|
||||
</view>
|
||||
</box>
|
||||
</showbox>
|
||||
</view>
|
||||
Reference in New Issue
Block a user