接口环境设置

This commit is contained in:
仲么了
2023-03-16 15:26:25 +08:00
parent 7e9cfadb23
commit c5ed54924b
20 changed files with 6480 additions and 37 deletions

21
App.vue
View File

@@ -1,7 +1,22 @@
<script>
import encrypt from './common/js/aes.js'
export default {
onLaunch: function () {
console.log('App Launch')
let cidAES = uni.getStorageSync('cidAES')
if (!cidAES) {
uni.getPushClientId({
success: (res) => {
console.log(res.cid);
uni.setStorageSync('cid', res.cid);
var cidAES = encrypt.Encrypt(res.cid, this.$config.key);
uni.setStorageSync('cidAES', cidAES);
},
fail (err) {
console.log(err)
}
})
}
},
onShow: function () {
console.log('App Show')
@@ -15,6 +30,7 @@ export default {
<style lang="scss">
/*每个页面公共css */
@import './common/css/base.scss';
/deep/ uni-tabbar .uni-tabbar__badge {
width: auto;
height: 28rpx;
@@ -24,7 +40,4 @@ export default {
font-size: 20rpx;
padding: 0 8rpx;
}
</style>

30
common/api/user.js Normal file
View File

@@ -0,0 +1,30 @@
import request from '../js/request'
export function apiGetYms (params) {
return request({
url: '/shiningCloud/user/authCode',
data: {
phone: params.phone,
devCode: uni.getStorageSync('cidAES'),
type: 0
},
method: 'POST'
})
}
/**
*
* @param {*} type 0:ysm 1:pwd
* @returns
*/
export function apiLogin (params) {
return request({
url: '/shiningCloud/user/login',
data: {
phone: params.phone,
devCode: uni.getStorageSync('cidAES'),
key: params.key.trim(),
type: params.type
},
method: 'POST'
})
}

36
common/js/aes.js Normal file
View File

@@ -0,0 +1,36 @@
import CryptoJS from './crypto.js'
// const key = CryptoJS.enc.Utf8.parse('1234123412ABCDEF') // 十六位十六进制数作为密钥
// const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412') // 十六位十六进制数作为密钥偏移量
// 解密方法
function Decrypt (word, key) {
let ckey = CryptoJS.enc.Utf8.parse(key) // 十六位十六进制数作为密钥
// let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
// let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
let decrypt = CryptoJS.AES.decrypt(word, ckey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
console.log('decryptedStr', decryptedStr.toString())
return decryptedStr.toString()
}
// 加密方法
function Encrypt (word, key) {
let ckey = CryptoJS.enc.Utf8.parse(key)
// let srcs = CryptoJS.enc.Utf8.parse(word)
let encrypted = CryptoJS.AES.encrypt(word, ckey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
export default {
Decrypt,
Encrypt
}

View File

@@ -1,32 +1,22 @@
const debug = false // true 是连地服务端本地false 是连接线上
const debug = true // true 是连地服务端本地false 是连接线上
const development = {
DOMAIN: 'http://192.168.1.60:8094',
MQTT_OPTIONS: {
clientId: '',
connectTimeout: 15000,
username: 'admin',
password: 'admin',
}
domain: 'http://pqmcc.com:8040',
devCode: "2aaecd0b124df819eda75e639a1f91fd",
key: "f81804778c89c779"
}
const production = {
DOMAIN: 'http://192.168.1.60:8094',
MQTT_OPTIONS: {
clientId: '',
connectTimeout: 15000,
username: 'admin',
password: 'admin',
}
domain: 'http://192.168.1.60:8094',
}
const config = debug ? development : production
// #ifdef H5
if (process.env.NODE_ENV === 'development') {
config.DOMAIN = '/api'
config.domain = '/api'
} else {
config.DOMAIN = window.location.origin
config.domain = window.location.origin
}
// #endif

5988
common/js/crypto.js Normal file

File diff suppressed because it is too large Load Diff

24
common/js/des.js Normal file
View File

@@ -0,0 +1,24 @@
import CryptoJS from '../js/crypto.js'
// DES加密
export const encryptDes = (message, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
// DES解密
export const decryptDes = (ciphertext, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
// direct decrypt ciphertext
const decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return decrypted.toString(CryptoJS.enc.Utf8);
}

View File

@@ -30,16 +30,12 @@ export default (options = {}) => {
},
method: options.method || 'GET',
success: async (res) => {
console.warn(res);
if (options.url.indexOf('/org/login/valid') > -1) {
uni.setStorageSync('Cookie', res.header['Set-Cookie']);
}
if (arr.indexOf(options.url) > -1) {
arr.splice(arr.indexOf(options.url), 1)
}
if (res.data.isOk === false) {
reject(res.data)
if (res.data.resultCode !== 10000) {
errHandler(res.data)
reject(res.data)
} else {
reslove(res.data)
}
@@ -66,7 +62,7 @@ export default (options = {}) => {
* @param {Number} code 错误码
*/
function errHandler (res) {
switch (res.code) {
switch (res.resultCode) {
case '401':
// #ifdef MP
uni.removeStorageSync('Cookie');

View File

@@ -196,6 +196,10 @@ const loadConfig = (call, need_fresh = false) => {
})
}
export default {
validatePhoneNumber,
toast,

View File

@@ -414,5 +414,16 @@
"custom": {
"^rc-(.*)": "@/components/Cn-$1/Cn-$1.vue"
}
},
"condition": {
//模式配置,仅开发期间生效
"current": 0, //当前激活的模式list 的索引项)
"list": [
{
"name": "login", //模式名称
"path": "pages/user/login", //启动页面,必选
"query": "" //启动参数在页面的onLoad函数里面得到。
}
]
}
}

View File

@@ -27,8 +27,7 @@
<input class="login-box-input-main" v-model="pwdForm.account" placeholder="请输入账号" />
</view>
<view class="login-box-input mt40">
<input type="password" class="login-box-input-main" v-model="pwdForm.pwd"
placeholder="请输入密码" />
<input type="password" class="login-box-input-main" v-model="pwdForm.pwd" placeholder="请输入密码" />
</view>
<!-- <view class="login-box-input mt40">
<view class="login-box-input-icon"></view>
@@ -56,6 +55,7 @@
</Cn-page>
</template>
<script>
import { apiGetYms, apiLogin } from '@/common/api/user'
export default {
data () {
return {
@@ -79,7 +79,15 @@ export default {
},
components: {},
methods: {
getCode () {
async getCode () {
if (!this.yzmForm.phone) {
return this.$util.toast('请输入手机号!')
}
const res = await apiGetYms({
phone: this.yzmForm.phone,
type: 0,
})
console.log(res);
this.waitTime = 60
this.inter = setInterval(() => {
if (this.waitTime == 0) {
@@ -90,6 +98,7 @@ export default {
}, 1000)
},
login () {
console.log(this.loginType);
if (this.loginType == 'pwd') {
this.pwdLogin()
} else {
@@ -97,24 +106,44 @@ export default {
}
},
pwdLogin () {
console.log({
phone: this.yzmForm.phone,
key: this.yzmForm.pwd,
type: 1,
})
if (!this.pwdForm.account && !this.pwdForm.pwd) {
return this.$util.toast('请填写登录信息!')
}
apiLogin({
phone: this.yzmForm.phone,
key: this.yzmForm.pwd,
type: 1,
}).then(res => {
console.log(res);
uni.setStorageSync('userInfo', res.data)
uni.reLaunch({
url: '/pages/index/index',
})
})
},
yzmLogin () {
if (!this.yzmForm.phone && !this.yzmForm.code) {
return this.$util.toast('请填写登录信息!')
}
apiLogin({
phone: this.yzmForm.phone,
key: this.yzmForm.code,
type: 0,
}).then(res => {
console.log(res);
uni.setStorageSync('userInfo', res.data)
uni.reLaunch({
url: '/pages/index/index',
})
})
},
},
onLoad (o) {
},
}
</script>

View File

@@ -0,0 +1,6 @@
## 0.0.32022-11-11
- 修复 config 方法获取根节点为数组格式配置时错误的转化为了对象的Bug
## 0.0.22021-04-16
- 修改插件package信息
## 0.0.12021-03-15
- 初始化项目

View File

@@ -0,0 +1,81 @@
{
"id": "uni-config-center",
"displayName": "uni-config-center",
"version": "0.0.3",
"description": "uniCloud 配置中心",
"keywords": [
"配置",
"配置中心"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "",
"type": "unicloud-template-function"
},
"directories": {
"example": "../../../scripts/dist"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "u"
}
}
}
}
}

View File

@@ -0,0 +1,93 @@
# 为什么使用uni-config-center
实际开发中很多插件需要配置文件才可以正常运行,如果每个插件都单独进行配置的话就会产生下面这样的目录结构
```bash
cloudfunctions
└─────common 公共模块
├─plugin-a // 插件A对应的目录
│ ├─index.js
│ ├─config.json // plugin-a对应的配置文件
│ └─other-file.cert // plugin-a依赖的其他文件
└─plugin-b // plugin-b对应的目录
├─index.js
└─config.json // plugin-b对应的配置文件
```
假设插件作者要发布一个项目模板,里面使用了很多需要配置的插件,无论是作者发布还是用户使用都是一个大麻烦。
uni-config-center就是用了统一管理这些配置文件的使用uni-config-center后的目录结构如下
```bash
cloudfunctions
└─────common 公共模块
├─plugin-a // 插件A对应的目录
│ └─index.js
├─plugin-b // plugin-b对应的目录
│ └─index.js
└─uni-config-center
├─index.js // config-center入口文件
├─plugin-a
│ ├─config.json // plugin-a对应的配置文件
│ └─other-file.cert // plugin-a依赖的其他文件
└─plugin-b
└─config.json // plugin-b对应的配置文件
```
使用uni-config-center后的优势
- 配置文件统一管理,分离插件主体和配置信息,更新插件更方便
- 支持对config.json设置schema插件使用者在HBuilderX内编写config.json文件时会有更好的提示后续HBuilderX会提供支持
# 用法
在要使用uni-config-center的公共模块或云函数内引入uni-config-center依赖请参考[使用公共模块](https://uniapp.dcloud.net.cn/uniCloud/cf-common)
```js
const createConfig = require('uni-config-center')
const uniIdConfig = createConfig({
pluginId: 'uni-id', // 插件id
defaultConfig: { // 默认配置
tokenExpiresIn: 7200,
tokenExpiresThreshold: 600,
},
customMerge: function(defaultConfig, userConfig) { // 自定义默认配置和用户配置的合并规则,不设置的情况侠会对默认配置和用户配置进行深度合并
// defaudltConfig 默认配置
// userConfig 用户配置
return Object.assign(defaultConfig, userConfig)
}
})
// 以如下配置为例
// {
// "tokenExpiresIn": 7200,
// "passwordErrorLimit": 6,
// "bindTokenToDevice": false,
// "passwordErrorRetryTime": 3600,
// "app-plus": {
// "tokenExpiresIn": 2592000
// },
// "service": {
// "sms": {
// "codeExpiresIn": 300
// }
// }
// }
// 获取配置
uniIdConfig.config() // 获取全部配置注意uni-config-center内不存在对应插件目录时会返回空对象
uniIdConfig.config('tokenExpiresIn') // 指定键值获取配置返回7200
uniIdConfig.config('service.sms.codeExpiresIn') // 指定键值获取配置返回300
uniIdConfig.config('tokenExpiresThreshold', 600) // 指定键值获取配置如果不存在则取传入的默认值返回600
// 获取文件绝对路径
uniIdConfig.resolve('custom-token.js') // 获取uni-config-center/uni-id/custom-token.js文件的路径
// 引用文件require
uniIDConfig.requireFile('custom-token.js') // 使用require方式引用uni-config-center/uni-id/custom-token.js文件。文件不存在时返回undefined文件内有其他错误导致require失败时会抛出错误。
// 判断是否包含某文件
uniIDConfig.hasFile('custom-token.js') // 配置目录是否包含某文件true: 文件存在false: 文件不存在
```

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
{
"name": "uni-config-center",
"version": "0.0.3",
"description": "配置中心",
"main": "index.js",
"keywords": [],
"author": "DCloud",
"license": "Apache-2.0"
}

View File

@@ -0,0 +1,28 @@
## 1.0.142023-03-07
- 修复 admin用户包含其他角色时未包含在token的Bug
## 1.0.132022-07-21
- 修复 创建token时未传角色权限信息生成的token不正确的bug
## 1.0.122022-07-15
- 提升与旧版本uni-id的兼容性补充读取配置文件时回退平台app-plus、h5但是仍推荐使用新平台名进行配置app、web
## 1.0.112022-07-14
- 修复 部分情况下报`read property 'reduce' of undefined`的错误
## 1.0.102022-07-11
- 将token存储在用户表的token字段内与旧版本uni-id保持一致
## 1.0.92022-07-01
- checkToken兼容token内未缓存角色权限的情况此时将查库获取角色权限
## 1.0.82022-07-01
- 修复clientDB默认依赖时部分情况下获取不到uni-id配置的Bug
## 1.0.72022-06-30
- 修复config文件不合法时未抛出具体错误的Bug
## 1.0.62022-06-28
- 移除插件内的数据表schema
## 1.0.52022-06-27
- 修复使用多应用配置时报`Cannot read property 'appId' of undefined`的Bug
## 1.0.42022-06-27
- 修复使用自定义token内容功能报错的Bug [详情](https://ask.dcloud.net.cn/question/147945)
## 1.0.22022-06-23
- 对齐旧版本uni-id默认配置
## 1.0.12022-06-22
- 补充对uni-config-center的依赖
## 1.0.02022-06-21
- 提供uni-id token创建、校验、刷新接口简化旧版uni-id公共模块

View File

@@ -0,0 +1,84 @@
{
"id": "uni-id-common",
"displayName": "uni-id-common",
"version": "1.0.14",
"description": "包含uni-id token生成、校验、刷新功能的云函数公共模块",
"keywords": [
"uni-id-common",
"uniCloud",
"token",
"权限"
],
"repository": "https://gitcode.net/dcloud/uni-id-common",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "",
"type": "unicloud-template-function"
},
"uni_modules": {
"dependencies": ["uni-config-center"],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
# uni-id-common
文档请参考:[uni-id-common](https://uniapp.dcloud.net.cn/uniCloud/uni-id-common.html)

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
{
"name": "uni-id-common",
"version": "1.0.14",
"description": "uni-id token生成、校验、刷新",
"main": "index.js",
"homepage": "https://uniapp.dcloud.io/uniCloud/uni-id-common.html",
"repository": {
"type": "git",
"url": "git+https://gitee.com/dcloud/uni-id-common.git"
},
"author": "DCloud",
"license": "Apache-2.0",
"dependencies": {
"uni-config-center": "file:../../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
}
}