This commit is contained in:
2025-09-14 00:21:54 +08:00
commit d40b3bbd62
766 changed files with 36275 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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));

View File

@@ -0,0 +1,8 @@
{
"navigationBarTitleText": "授权",
"usingComponents": {
"showbox": "../../common/component/showbox/index",
"box": "../../common/component/container/index",
"api-status": "../../common/component/api-status/index"
}
}

View File

@@ -0,0 +1,117 @@
<view class="container">
<showbox title="登录">
<box>
<view class="setting-title">
点击下方按钮进行登录
</view>
<button
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="login"
>登录</button>
</box>
</showbox>
<showbox title="getUserInfo">
<box>
<view class="setting-title">
点击下方按钮进行getUserInfo
</view>
<button
class="_ui-button"
hover-class="_ui-button-hover"
open-type="getUserInfo"
bindgetuserinfo="handleUserInfo"
>getUserInfo</button>
</box>
</showbox>
<showbox title="用户信息授权">
<box>
<view class="setting-title">
点击下方按钮进行授权
</view>
<button
data-scope="scope.userInfo"
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="handleAuthorize"
>授权</button>
</box>
</showbox>
<showbox title="手机号授权">
<box>
<view class="setting-title">
点击下方按钮进行授权
</view>
<button
open-type="getPhoneNumber"
class="_ui-button"
hover-class="_ui-button-hover"
bindgetphonenumber="getPhoneNumber"
>授权</button>
</box>
</showbox>
<showbox title="地理位置授权">
<box>
<view class="setting-title">
点击下方按钮进行授权
</view>
<button
data-scope="scope.userLocation"
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="handleAuthorize"
>授权</button>
</box>
</showbox>
<showbox title="保存相册授权">
<box>
<view class="setting-title">
点击下方按钮进行授权
</view>
<button
data-scope="scope.writePhotosAlbum"
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="handleAuthorize"
>授权</button>
</box>
</showbox>
<showbox title="摄像头授权">
<box>
<view class="setting-title">
点击下方按钮进行授权
</view>
<button
data-scope="scope.camera"
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="handleAuthorize"
>授权</button>
</box>
</showbox>
<showbox title="小红书权限设置">
<box>
<view class="_ui-space">
<button
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="getSetting"
>获取小程序设置</button>
<button
bindtap="openSetting"
class="_ui-button"
hover-class="_ui-button-hover"
>打开小程序设置</button>
</view>
</box>
</showbox>
</view>
<include src="templates.xhsml" />

View File

@@ -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,
});
},
});
},
};

View File

@@ -0,0 +1,70 @@
<!-- 以下内容为自动生成,请勿手动修改 -->
<view class="container">
<showbox title="authorize演示">
<box>
<api-status
success="{{page_data_1}}"
complete="{{page_data_3}}"
fail="{{page_data_2}}"
text="{{page_data_4}}"
>
</api-status>
<view class="_ui-space _mt8">
<view class="_ui-input">
<input placeholder="scope" type="text" bindinput="page_fun_1" />
</view>
<button
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="page_fun_0"
>
触发
</button>
</view>
</box>
</showbox>
<showbox title="getSetting演示">
<box>
<api-status
success="{{page_data_5}}"
complete="{{page_data_7}}"
fail="{{page_data_6}}"
text="{{page_data_8}}"
>
</api-status>
<view class="_ui-space _mt8">
<button
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="page_fun_2"
>
触发
</button>
</view>
</box>
</showbox>
<showbox title="openSetting演示">
<box>
<api-status
success="{{page_data_9}}"
complete="{{page_data_11}}"
fail="{{page_data_10}}"
text="{{page_data_12}}"
>
</api-status>
<view class="_ui-space _mt8">
<button
class="_ui-button"
hover-class="_ui-button-hover"
bindtap="page_fun_3"
>
触发
</button>
</view>
</box>
</showbox>
</view>