mrr.sj.front/utils/version.js

73 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let VersionCode = '';
let DeviceType = '';
let platform = ''
export function setVersion() {
// 获取当前app的版本
const systemInfo = uni.getSystemInfoSync();
// 应用程序版本号
// 条件编译只在APP渲染
// #ifdef APP
VersionCode = systemInfo.appWgtVersion;
// #endif
// #ifdef H5
VersionCode = systemInfo.appVersion;
// VersionCode = "1.2.17" // 用于开发
console.log(systemInfo.appVersion, '版本号');
// #endif
// #ifdef MP-WEIXIN
const accountInfo = uni.getAccountInfoSync();
VersionCode = accountInfo.miniProgram.version // 小程序 版本号
console.log(accountInfo.miniProgram.version, '小程序版本号')
// #endif
// 获取手机型号
DeviceType = systemInfo.deviceBrand;
console.log('DeviceType', DeviceType)
//获取运行环境
platform = systemInfo.platform
if (platform === 'android') {
platform = "yh_android"
} else if (platform === 'ios') {
platform = "yh_ios"
} else {
// console.log('平台未知')
}
let data = {
'VersionCode': VersionCode ? VersionCode : '',
'DeviceBrand': platform ? platform : '',
'DeviceType': DeviceType ? DeviceType : ''
}
uni.setStorageSync('setVersion', data)
// store.commit('setVersion',data)
// store.state.version = data
}
export async function getBaseUrl() {
let version = uni.getStorageSync('setVersion')
await uni.request({
url: 'https://app.mrrweb.com.cn/api/openPuc/getApiUrl', // 接口地址
method: 'GET', // 请求方法(默认 GET
header: {
'Content-Type': 'application/json', // 请求头
'VersionCode': version.VersionCode,
'DeviceBrand': version.DeviceBrand,
'DeviceType': version.DeviceType
},
success: (res) => {
if (res.data.code == 200) {
uni.setStorageSync('baseUrl', res.data.data.url)
// store.commit('setBaseUrl', res.data.data.url)
}
return res.data.data.url;
console.log('请求成功', res.data);
},
fail: (err) => {
console.log('请求失败', err);
return 'http://60.247.146.5:93';
},
complete: () => {
console.log('请求完成(无论成功失败都会执行)');
}
});
}