提交 663d00c0 编写于 作者: DCloud_JSON's avatar DCloud_JSON

新增一键登陆的第三方快捷登陆按钮

上级 d0706a84
......@@ -195,7 +195,11 @@
},
err => {
uni.hideLoading()
console.log(err);
console.log(err);
uni.showModal({
content: JSON.stringify(err),
showCancel: false
});
})
}
// #endif
......@@ -229,7 +233,7 @@
console.log(err);
if (type == 'univerify') {
if (err.metadata.error_data) {
if (err.metadata&&err.metadata.error_data) {
uni.showToast({
title: "一键登录:" + err.metadata.error_data,
icon: 'none'
......@@ -245,15 +249,33 @@
uni.navigateBack()
}
break;
case 30006:
uni.showModal({
title: "登录服务初始化错误",
content: err.metadata.error_data,
showCancel: false,
confirmText: '知道了',
});
case 30006:
uni.showModal({
title: "登录服务初始化错误",
content: err.metadata.error_data,
showCancel: false,
confirmText: '知道了',
});
break;
case "30008":
uni.showToast({
title: '点击了第三方登陆',
icon: 'none'
});
switch (err.index){
case 0:
this.login_before('weixin',false)
break;
case 1:
this.login_before('apple',false)
break;
default:
break;
}
break;
default:
default:
console.log(9527,err);
break;
}
}
......
{
"name" : "uni-starter",
"appid" : "",
"description" : "云端一体应用快速开发模版",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
"app-plus" : {
"privacy" : {
"prompt" : "template",
"template" : {
"title" : "服务协议和隐私政策",
"message" : "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href=\"https://ask.dcloud.net.cn/protocol.html\">《服务协议》</a>和<a href=\"https://ask.dcloud.net.cn/protocol.html\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
"buttonAccept" : "同意",
"buttonRefuse" : "暂不同意"
}
"name": "uni-starter",
"appid": "",
"description": "云端一体应用快速开发模版",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"app-plus": {
"privacy": {
"prompt": "template",
"template": {
"title": "服务协议和隐私政策",
"message": "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href=\"https://ask.dcloud.net.cn/protocol.html\">《服务协议》</a>和<a href=\"https://ask.dcloud.net.cn/protocol.html\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
"buttonAccept": "同意",
"buttonRefuse": "暂不同意"
}
},
"compatible": {
"ignoreVersion": true
},
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
"modules": {
"Fingerprint": {
},
"Share": {
},
"Push": {
},
"OAuth": {
},
"FaceID": {
}
},
"distribute": {
"android": {
"permissions": [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.USE_FINGERPRINT\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters": [
"armeabi-v7a",
"arm64-v8a",
"x86"
]
},
"ios": {
},
"sdkConfigs": {
"oauth": {
"univerify": {
},
"apple": {
},
"weixin": {
"appid": "wxffdd8fa6ec4ef2a0",
"appsecret": "",
"UniversalLinks": ""
}
},
"compatible" : {
"ignoreVersion" : true
"ad": {
},
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
"share": {
"weixin": {
"appid": "wxffdd8fa6ec4ef2a0",
"UniversalLinks": ""
}
},
"modules" : {
"Fingerprint" : {},
"Share" : {},
"Push" : {},
"OAuth" : {}
"geolocation": {
},
"distribute" : {
"android" : {
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.USE_FINGERPRINT\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
},
"ios" : {},
"sdkConfigs" : {
"oauth" : {
"univerify" : {},
"apple" : {},
"weixin" : {
"appid" : "32234",
"appsecret" : "3223",
"UniversalLinks" : ""
}
},
"ad" : {},
"share" : {},
"geolocation" : {},
"push" : {
"unipush" : {}
},
"payment" : {}
}
"push": {
"unipush": {
}
},
"nvueLaunchMode" : ""
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false,
"es6" : false
},
"usingComponents" : true,
"betterScopedSlots" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
"payment": {
}
}
},
"uniStatistics" : {
"enable" : false
"nvueLaunchMode": ""
},
"quickapp": {
},
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false,
"es6": false
},
"h5" : {
"template" : ""
}
}
"usingComponents": true,
"betterScopedSlots": true
},
"mp-alipay": {
"usingComponents": true
},
"mp-baidu": {
"usingComponents": true
},
"mp-toutiao": {
"usingComponents": true
},
"uniStatistics": {
"enable": false
},
"h5": {
"template": ""
}
}
\ No newline at end of file
......@@ -27,10 +27,7 @@
"buttons": { // 自定义登陆按钮
"iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
"list": [{
"iconPath": "/static/apple.png" // 图标路径仅支持本地图片
},
{
"iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
"iconPath": "/static/uni-quick-login/wechat.png" // 图标路径仅支持本地图片
}
]
}
......@@ -42,7 +39,19 @@
return /^1\d{10}$/.test(this.phone);
}
},
onLoad(e) {
onLoad(e) {
uni.getProvider({
service: 'oauth',
success:res=>{
if (~res.provider.indexOf('apple')) {
this.univerifyStyle.buttons.list.push({
"iconPath": "/static/uni-quick-login/apple.png" // 图标路径仅支持本地图片
})
}
}
});
//是否优先启动一键登录。即:页面一加载就启动一键登录
univerify_first = e.univerify_first
//#ifdef APP-PLUS
......
{
"scripts": {
"preupload": "node /Users/dcloud_linju/Desktop/uni_modules_tool/tool.js change",
"postupload": "node /Users/dcloud_linju/Desktop/uni_modules_tool/tool.js recovery"
"preupload": "node uni_modules_tools/main.js change",
"postupload": "node uni_modules_tools/main.js recovery"
}
}
\ No newline at end of file
/*
重要的事情说三遍:
本文件不能有任何注释,删除后才能正常使用
本文件不能有任何注释,删除后才能正常使用
本文件不能有任何注释,删除后才能正常使用
*/
{
"passwordSecret": "passwordSecret-demo", // 数据库中password字段是加密存储的,这里的passwordSecret即为加密密码所用的密钥,注意修改为自己的密钥,使用一个较长的字符串即可
"tokenSecret": "tokenSecret-demo", // 生成token所用的密钥,注意修改为自己的,使用一个较长的字符串即可
"tokenExpiresIn": 7200, // 全平台token过期时间,未指定过期时间的平台会使用此值
"tokenExpiresThreshold": 600, // 新增于uni-id 1.1.7版本,checkToken时如果token有效期小于此值则自动获取新token,请注意将新token返回给前端保存,如果不配置此参数则不开启自动获取新token功能
"bindTokenToDevice": false, // 是否将token和设备绑定,设置为true会进行ua校验,uni-id 3.0.12前默认为true3.0.12及以后版本默认调整为false
"passwordErrorLimit": 6, // 密码错误最大重试次数
"passwordErrorRetryTime": 3600, // 密码错误重试次数超限之后的冻结时间
"autoSetInviteCode": false, // 是否在用户注册时自动设置邀请码,默认不自动设置
"forceInviteCode": false, // 是否强制用户注册时必填邀请码,默认为false(需要注意的是目前只有短信验证码注册才可以填写邀请码),设置为true时需要在loginBySms时指定type为register来使用注册,登录时也要传入type为login
"removePermissionAndRoleFromToken": false, // 新增于uni-id 3.0.0版本,如果配置为false则自动缓存用户的角色、权限到token中,默认值为false。详细说明见https://uniapp.dcloud.io/uniCloud/uni-id?id=cachepermissionintoken
"app-plus": {
"tokenExpiresIn": 2592000,
"oauth": {
// App微信登录所用到的appid、appsecret需要在微信开放平台获取,注意:不是公众平台而是开放平台
"weixin": {
"appid": "weixin appid",
"appsecret": "weixin appsecret"
},
"apple": { // 使用苹果登录时需要
"bundleId": "your bundleId"
}
}
},
"mp-weixin": {
"tokenExpiresIn": 259200,
"oauth": {
// 微信小程序登录所用的appid、appsecret需要在对应的小程序管理控制台获取
"weixin": {
"appid": "weixin appid",
"appsecret": "weixin appsecret"
}
}
},
"mp-alipay": {
"tokenExpiresIn": 259200,
"oauth": {
// 支付宝小程序登录用到的appid、privateKey请参考支付宝小程序的文档进行设置或者获取,https://opendocs.alipay.com/open/291/105971#LDsXr
"alipay": {
"appid": "alipay appid",
"privateKey": "alipay privateKey", // 私钥
"keyType": "PKCS8" // 私钥类型,如果私钥类型不是PKCS8,需要填写此字段,否则会出现“error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag”错误
}
}
},
"service": {
"sms": {
"name": "your app name", // 应用名称,对应短信模版的name
"codeExpiresIn": 180, // 验证码过期时间,单位为秒,注意一定要是60的整数倍
"smsKey": "your sms key", // 短信密钥key,开通短信服务处可以看到
"smsSecret": "your sms secret" // 短信密钥secret,开通短信服务处可以看到
},
"univerify": {
"appid": "your appid", // 当前应用的appid,使用云函数URL化,此项必须配置
"apiKey": "your apiKey",// apiKey apiSecret 在开发者中心获取,开发者中心:https://dev.dcloud.net.cn/uniLogin/index?type=0,文档:https://ask.dcloud.net.cn/article/37965
"apiSecret": "your apiSecret"
}
}
{
"passwordSecret": "passwordSecret-demo",
"tokenSecret": "tokenSecret-demo",
"tokenExpiresIn": 7200,
"tokenExpiresThreshold": 600,
"passwordErrorLimit": 6,
"bindTokenToDevice": true,
"passwordErrorRetryTime": 3600,
"autoSetInviteCode": false,
"forceInviteCode": false,
"app-plus": {
"tokenExpiresIn": 2592000,
"oauth": {
"weixin": {
"appid": "",
"appsecret": ""
},
"apple": {
"bundleId": ""
}
}
},
"mp-weixin": {
"oauth": {
"weixin": {
"appid": "",
"appsecret": ""
}
}
},
"mp-alipay": {
"oauth": {
"alipay": {
"appid": "",
"privateKey": ""
}
}
},
"service": {
"sms": {
"name": "",
"codeExpiresIn": 300,
"smsKey": "",
"smsSecret": ""
},
"univerify": {
"appid": "",
"apiKey": "",
"apiSecret": ""
}
}
}
\ No newline at end of file
// "文件路径" : {"键名":"改成什么"}
{
"/manifest.json": {
"appid": "" //清空appid
},
"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json": {
"app-plus": {
"oauth": {
"weixin": {
"appid": "",
"appsecret": ""
},
"apple": {
"bundleId": ""
}
}
},
"mp-weixin": {
"oauth": {
"weixin": {
"appid": "",
"appsecret": ""
}
}
},
"mp-alipay": {
"oauth": {
"alipay": {
"appid": "",
"privateKey": ""
}
}
},
"service": {
"sms": {
"name": "",
"smsKey": "",
"smsSecret": ""
},
"univerify": {
"appid": "",
"apiKey": "",
"apiSecret": ""
}
}
}
}
\ No newline at end of file
{
"name" : "uni-starter",
"appid" : "__UNI__03B096E",
"description" : "云端一体应用快速开发模版",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
"app-plus" : {
"privacy" : {
"prompt" : "template",
"template" : {
"title" : "服务协议和隐私政策",
"message" : "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href=\"https://ask.dcloud.net.cn/protocol.html\">《服务协议》</a>和<a href=\"https://ask.dcloud.net.cn/protocol.html\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
"buttonAccept" : "同意",
"buttonRefuse" : "暂不同意"
}
},
"compatible" : {
"ignoreVersion" : true
},
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
"modules" : {
"Fingerprint" : {},
"Share" : {},
"Push" : {},
"OAuth" : {},
"FaceID" : {}
},
"distribute" : {
"android" : {
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.USE_FINGERPRINT\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
},
"ios" : {},
"sdkConfigs" : {
"oauth" : {
"univerify" : {},
"apple" : {},
"weixin" : {
"appid" : "wxffdd8fa6ec4ef2a0",
"appsecret" : "",
"UniversalLinks" : ""
}
},
"ad" : {},
"share" : {
"weixin" : {
"appid" : "wxffdd8fa6ec4ef2a0",
"UniversalLinks" : ""
}
},
"geolocation" : {},
"push" : {
"unipush" : {}
},
"payment" : {}
}
},
"nvueLaunchMode" : ""
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false,
"es6" : false
},
"usingComponents" : true,
"betterScopedSlots" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics" : {
"enable" : false
},
"h5" : {
"template" : ""
}
}
{
"passwordSecret": "passwordSecret-demo",
"tokenSecret": "tokenSecret-demo",
"tokenExpiresIn": 7200,
"tokenExpiresThreshold": 600,
"passwordErrorLimit": 6,
"bindTokenToDevice": true,
"passwordErrorRetryTime": 3600,
"autoSetInviteCode": false,
"forceInviteCode": false,
"app-plus": {
"tokenExpiresIn": 2592000,
"oauth": {
"weixin": {
"appid": "wxffdd8fa6ec4ef2a0",
"appsecret": "6c9119430d7be0a147bcbbb73ef33acf"
},
"apple": {
"bundleId": "io.dcloud.hellouniapp"
}
}
},
"mp-weixin": {
"oauth": {
"weixin": {
"appid": "wx81dbb061d2258234",
"appsecret": "73be6e8b8b31b7b0783fe448cc1fe820"
}
}
},
"mp-alipay": {
"oauth": {
"alipay": {
"appid": "alipay appid",
"privateKey": "alipay privateKey"
}
}
},
"service": {
"sms": {
"name": "DCloud",
"codeExpiresIn": 300,
"smsKey": "71a19f38c954f7d768d68a050486bf15",
"smsSecret": "d6c424b702d73baa3b6e1a1452469213"
},
"univerify": {
"appid": "__UNI__03B096E",
"apiKey": "3fc28519d90d74173bcecf2daf4ffcc4",
"apiSecret": "dd793e5bc4b372ce932f35bbb4c5d61b"
}
}
}
\ No newline at end of file
//脚本文件目录 __dirname
//运行脚本的目录,即:项目的目录 process.cwd()
//配置文件
const fs = require('fs'),
Hjson = require('hjson'),
config = Hjson.rt.parse(fs.readFileSync(__dirname+'/config.js', 'utf-8'))
if(process.argv[2] == 'change'){
change(config)
}else{
recovery(config)
}
function change(config){
for (let fileName in config) {
let path = process.cwd() + fileName
let copyPath = __dirname + '/copy' + fileName
let fileText = fs.readFileSync(path, 'utf-8')
//保持原文件名先备份一份到脚本目录下
writeFileRecursive(copyPath, fileText, function(err) {
if (err) {
return console.log(err);
}
//改写
let HfileObj = Hjson.rt.parse(fileText)
mergeJSON(HfileObj,config[fileName])
fs.writeFile(path, Hjson.rt.stringify(HfileObj, {
quotes: 'all',
separator: true,
multiline: "off",
bracesSameLine: true
}), function(err) {
if (err) {
return console.log(err);
}
})
})
}
}
function recovery(){
let paths = Object.keys(config)
console.log(paths);
paths.forEach(path=>{
console.log(__dirname + '/copy' + path);
let oldFile = fs.readFileSync(__dirname + '/copy' + path)
console.log(process.cwd() + path);
fs.writeFile(process.cwd() + path, oldFile, function(err) {
if (err) {
console.log(err);
return
}
// fs.unlinkSync(__dirname + path+'.lock')
})
})
}
//创建目录并写入文件
function writeFileRecursive(path, buffer, callback) {
let lastPath = path.substring(0, path.lastIndexOf("/"));
fs.mkdir(lastPath, {
recursive: true
}, (err) => {
if (err) return callback(err);
fs.writeFile(path, buffer, function(err) {
if (err) return callback(err);
return callback(null);
});
});
}
//递归合并,为了保留注释内容
function mergeJSON(minor, main) {
for (var key in main) {
if (typeof(main[key]) != 'object' ) {
minor[key] = main[key];
}else{
mergeJSON(minor[key], main[key]);
}
}
}
\ No newline at end of file
{
"name": "uni_modules_tools",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"hjson": "^3.2.2"
}
},
"node_modules/hjson": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz",
"integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q==",
"bin": {
"hjson": "bin/hjson"
}
}
},
"dependencies": {
"hjson": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz",
"integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q=="
}
}
}
{
"name": "uni_modules_tools",
"version": "1.0.0",
"description": "本插件是一个[uni_modules钩子脚本](https://uniapp.dcloud.io/uni_modules?id=uni_modulesconfigjson),仅限uni_modules插件使用 #### 为什么使用 uni_modules_tools 在实际开发中很多插件需要配置文件才可以正常运行,比如uni-id、uni-pay等; 有些配置内容属于密钥,在发表到插件市场的时候我们通常不希望这些配置被暴露。 传统的方式你需要手动备份密钥内容,上传结束后再将配置填回。这样插件作者发表插件会比较不便。",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hjson": "^3.2.2"
}
}
本插件是一个[uni_modules钩子脚本](https://uniapp.dcloud.io/uni_modules?id=uni_modulesconfigjson),仅限uni_modules插件使用
#### 为什么使用 uni_modules_tools
在实际开发中很多插件需要配置文件才可以正常运行,比如uni-id、uni-pay等;
有些配置内容属于密钥,在发表到插件市场的时候我们通常不希望这些配置被暴露。
传统的方式你需要手动备份密钥内容,上传结束后再将配置填回。这样插件作者发表插件会比较不便。
而现在有了 `uni_modules_tools` 只需配置`/uni_modules_tools/config.js`即实现
- 在插件上传之前,自动根据配置改写项目中对应配置。
- 上传结束(成功和失败都触发)后自动恢复项目中的配置。
#### 示例目录结构
<pre>
├─ uni_modules // 存放uni_module规范的插件。
│ └─uni-config-center
│ └─uniCloud
│ └─cloudfunctions
│ └─common
│ └─uni-config-center
│ └─uni-id
│ └─config.json
├─ manifest.json
├─ uni_modules.config.json //uni_modules的配置文件
└─ uni_modules_tools
├─ copy //用于自动修改配置文件时的,临时备份目录
├─ config.js //插件配置文件,下面会有示例说明
├─ main.js //插件核心代码,入口文件;你无需修改此文件中的代码,除非你了解内部逻辑
└─ readme.md //插件文档
</pre>
#### 使用方式
`/uni_modules_tools/config.js`的格式为:
```
{
"文件路径" : {"键名":"改后的内容"}
}
```
- 文件仅支持json格式,如:`manifest.json``uni-config-center`下的`config.json`
使用示例,比如你需要:
- 修改manifest.json文件的appid内容改为:请重新获取appid
- 修改uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json 文件的内容app-plus -> oauth -> weixin 和 apple 下的 `appid` `appsecret` `apple`值为:`请填写你的自己的appid` `请填写你的自己的appsecret` `请填写你的自己的bundleId`
1. 配置,根目录下的`/uni_modules_tools/config.js`文件,如下:
```
{
"/manifest.json": {
"appid": "请重新获取appid"
},
"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json": {
"app-plus": {
"oauth": {
"weixin": {
"appid": "请填写你的自己的appid",
"appsecret": "请填写你的自己的appsecret"
},
"apple": {
"bundleId": "请填写你的自己的bundleId"
}
}
}
}
}
```
2. 根目录下的`/uni_modules.config.json`配置如下:
```
{
"scripts":{
"preupload": "node uni_modules_tools/main.js change",
"postupload": "node uni_modules_tools/main.js recovery"
}
}
```
3. 项目依赖hjson-js需要在uni_modules_tools目录,执行npm install完成依赖的安装
#### 测试方式
- 在项目根目录直接执行 `node uni_modules_tools/main.js change` 即可测试修改相关配置的效果
- 在项目根目录直接执行 `node uni_modules_tools/main.js recovery` 即可测试恢复相关配置的效果
> 本插件中使用了[hjson-js](https://www.npmjs.com/package/hjson) 感谢@hjson-js的作者
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册