在小程序开发版和体验版添加切换环境功能
This commit is contained in:
parent
8c028e0905
commit
fbff1e5cef
17
App.vue
17
App.vue
@ -14,7 +14,22 @@
|
|||||||
// 账号信息
|
// 账号信息
|
||||||
appid: '',
|
appid: '',
|
||||||
// 小程序版本
|
// 小程序版本
|
||||||
envVersion: ''
|
envVersion: '',
|
||||||
|
// 获取环境配置
|
||||||
|
getEnvConfig() {
|
||||||
|
const envVserionStorage = uni.getStorageSync('envVersion')
|
||||||
|
if(envVserionStorage) {
|
||||||
|
return envVserionStorage
|
||||||
|
} else {
|
||||||
|
if(this.envVersion === 'develop') {
|
||||||
|
return 'DEV'
|
||||||
|
} else if(this.envVersion === 'trial') {
|
||||||
|
return 'PRE'
|
||||||
|
} else {
|
||||||
|
return 'PROD'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useBluetoothStore, ['bluetoothStatus']),
|
...mapState(useBluetoothStore, ['bluetoothStatus']),
|
||||||
|
|||||||
@ -1,26 +1,30 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
const version = '1.0.0'
|
const version = '1.0.0'
|
||||||
|
const buildNumber = 0
|
||||||
|
|
||||||
const DEV = {
|
const DEV = {
|
||||||
name: '开发',
|
name: '开发',
|
||||||
baseUrl: 'https://dev.lock.star-lock.cn/api',
|
baseUrl: 'https://dev.lock.star-lock.cn/api',
|
||||||
webviewBaseUrl: 'https://dev.lock.star-lock.cn',
|
webviewBaseUrl: 'https://dev.lock.star-lock.cn',
|
||||||
version: version
|
version,
|
||||||
|
buildNumber
|
||||||
}
|
}
|
||||||
const PRE = {
|
const PRE = {
|
||||||
name: '预发',
|
name: '预发',
|
||||||
baseUrl: 'https://pre.lock.star-lock.cn/api',
|
baseUrl: 'https://pre.lock.star-lock.cn/api',
|
||||||
webviewBaseUrl: 'https://pre.lock.star-lock.cn',
|
webviewBaseUrl: 'https://pre.lock.star-lock.cn',
|
||||||
version: version
|
version,
|
||||||
|
buildNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
const PROD = {
|
const PROD = {
|
||||||
name: '线上',
|
name: '线上',
|
||||||
baseUrl: 'https://lock.xhjcn.ltd/api',
|
baseUrl: 'https://lock.xhjcn.ltd/api',
|
||||||
webviewBaseUrl: 'https://lock.xhjcn.ltd',
|
webviewBaseUrl: 'https://lock.xhjcn.ltd',
|
||||||
version: version
|
version,
|
||||||
|
buildNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更换环境的时候 切换导出就行
|
// 更换环境的时候 切换导出就行
|
||||||
export default DEV
|
export default { DEV, PRE, PROD }
|
||||||
|
|||||||
@ -31,6 +31,10 @@
|
|||||||
<image class="icon-arrow" src="/static/images/icon_arrow.png" mode="aspectFill"></image>
|
<image class="icon-arrow" src="/static/images/icon_arrow.png" mode="aspectFill"></image>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="env" v-if="envVersion !== 'release' && env">
|
||||||
|
<view class="env-text">{{env.name}}环境 版本号:{{env.version}}+{{env.buildNumber}}</view>
|
||||||
|
<view class="env-button" @click="show=true">切换环境</view>
|
||||||
|
</view>
|
||||||
<label for="changePhone">
|
<label for="changePhone">
|
||||||
<view class="switch-account">切换账号</view>
|
<view class="switch-account">切换账号</view>
|
||||||
</label>
|
</label>
|
||||||
@ -40,11 +44,17 @@
|
|||||||
<label for="phone">
|
<label for="phone">
|
||||||
<view class="button-login">登录</view>
|
<view class="button-login">登录</view>
|
||||||
</label>
|
</label>
|
||||||
|
<view class="env" v-if="envVersion !== 'release' && env">
|
||||||
|
<view class="env-text">{{env.name}}环境 版本号:{{env.version}}+{{env.buildNumber}}</view>
|
||||||
|
<view class="env-button" @click="show=true">切换环境</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<button open-type="contact" style="display:none" id="contact"></button>
|
<button open-type="contact" style="display:none" id="contact"></button>
|
||||||
<button open-type="getPhoneNumber" style="display:none" id="phone" @getphonenumber="getphonenumber"></button>
|
<button open-type="getPhoneNumber" style="display:none" id="phone" @getphonenumber="getphonenumber"></button>
|
||||||
<button open-type="getPhoneNumber" style="display:none" id="changePhone" @getphonenumber="changePhone"></button>
|
<button open-type="getPhoneNumber" style="display:none" id="changePhone" @getphonenumber="changePhone"></button>
|
||||||
|
<up-action-sheet :actions="envList" :closeOnClickOverlay="true" title="切换环境" cancelText="取消" :closeOnClickAction="true"
|
||||||
|
:show="show" :safeAreaInsetBottom="true" @close="show=false" @select="selectEnv"></up-action-sheet>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -53,11 +63,16 @@
|
|||||||
import { useLockStore } from '@/stores/lock'
|
import { useLockStore } from '@/stores/lock'
|
||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
import { phoneLoginRequest } from '@/api/user'
|
import { phoneLoginRequest } from '@/api/user'
|
||||||
|
import env from '@/config/env'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
buttonInfo: null
|
buttonInfo: null,
|
||||||
|
env: null,
|
||||||
|
envVersion: '',
|
||||||
|
envList: [],
|
||||||
|
show: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -66,12 +81,29 @@
|
|||||||
},
|
},
|
||||||
async onLoad() {
|
async onLoad() {
|
||||||
this.buttonInfo = await this.getButtonInfo()
|
this.buttonInfo = await this.getButtonInfo()
|
||||||
|
this.env = env[getApp().globalData.getEnvConfig()]
|
||||||
|
this.envVersion = getApp().globalData.envVersion
|
||||||
|
for (let key in env) {
|
||||||
|
this.envList.push({
|
||||||
|
...env[key],
|
||||||
|
key: key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
console.log(this.envList)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useBasicStore, ['getButtonInfo', 'routeJump']),
|
...mapActions(useBasicStore, ['getButtonInfo', 'routeJump']),
|
||||||
...mapActions(useLockStore, ['getLockList', 'updateLockSearch']),
|
...mapActions(useLockStore, ['getLockList', 'updateLockSearch']),
|
||||||
...mapActions(useUserStore, ['updateLoginStatus', 'phoneLogin', 'updateUserInfo', 'getUserInfo',
|
...mapActions(useUserStore, ['updateLoginStatus', 'phoneLogin', 'updateUserInfo', 'getUserInfo',
|
||||||
'checkSession']),
|
'checkSession']),
|
||||||
|
selectEnv(env) {
|
||||||
|
uni.setStorageSync('envVersion', env.key)
|
||||||
|
uni.removeStorageSync('token')
|
||||||
|
uni.removeStorageSync('openid')
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/home/home'
|
||||||
|
})
|
||||||
|
},
|
||||||
async changePhone(res) {
|
async changePhone(res) {
|
||||||
if(res.detail.errMsg === 'getPhoneNumber:fail user deny') {
|
if(res.detail.errMsg === 'getPhoneNumber:fail user deny') {
|
||||||
return
|
return
|
||||||
@ -203,6 +235,32 @@ page {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.env {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 180rpx;
|
||||||
|
width: 600rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
text-align: center;
|
||||||
|
margin-left: 75rpx;
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
|
||||||
|
.env-text {
|
||||||
|
color: #999999;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.env-button {
|
||||||
|
border-radius: 46rpx;
|
||||||
|
background: #f0ad4e;
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
width: 600rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.button-login {
|
.button-login {
|
||||||
border-radius: 46rpx;
|
border-radius: 46rpx;
|
||||||
width: 650rpx;
|
width: 650rpx;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import baseConfig from '@/config/env'
|
import env from '@/config/env'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* config
|
* config
|
||||||
@ -12,10 +12,12 @@ import baseConfig from '@/config/env'
|
|||||||
|
|
||||||
const request = (config) => {
|
const request = (config) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
const baseConfig = env[getApp().globalData.getEnvConfig()]
|
||||||
|
|
||||||
const token = config?.token ? config.token : uni.getStorageSync('token')
|
const token = config?.token ? config.token : uni.getStorageSync('token')
|
||||||
const headerDefault = {
|
const headerDefault = {
|
||||||
appid: getApp().globalData.appid,
|
appid: getApp().globalData.appid,
|
||||||
version: baseConfig.version,
|
version: baseConfig.version + '+' + baseConfig.buildNumber,
|
||||||
authorization: `Bearer ${token}`
|
authorization: `Bearer ${token}`
|
||||||
}
|
}
|
||||||
const URL = config.baseUrl ? config.baseUrl + config.url : baseConfig.baseUrl + config.url
|
const URL = config.baseUrl ? config.baseUrl + config.url : baseConfig.baseUrl + config.url
|
||||||
@ -63,13 +65,8 @@ const request = (config) => {
|
|||||||
resolve({ code: -1, data, message: '网络不太好哦,请稍后再试' })
|
resolve({ code: -1, data, message: '网络不太好哦,请稍后再试' })
|
||||||
},
|
},
|
||||||
async complete(res) {
|
async complete(res) {
|
||||||
const env =
|
|
||||||
baseConfig.baseUrl.indexOf('test') !== -1
|
|
||||||
? 'test'
|
|
||||||
: baseConfig.baseUrl.indexOf('pre') !== -1
|
|
||||||
? 'pre'
|
|
||||||
: 'release'
|
|
||||||
console.log(URL.substring(baseConfig.baseUrl.length + 1), {
|
console.log(URL.substring(baseConfig.baseUrl.length + 1), {
|
||||||
|
env: getApp().globalData.getEnvConfig(),
|
||||||
url: URL.substring(baseConfig.baseUrl.length + 1),
|
url: URL.substring(baseConfig.baseUrl.length + 1),
|
||||||
req: config?.data || {},
|
req: config?.data || {},
|
||||||
code: res?.data?.errorCode,
|
code: res?.data?.errorCode,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user