Commit 5cab1b96 by liimin

fix(mp/store,sales): 引入 systemInfo 兼容层替换废弃 getSystemInfo

与 usedcar 保持一致,新增 apps/mp/{store,sales}/utils/systemInfo.js 兼容层
(合并 getDeviceInfo/getWindowInfo/getAppBaseInfo,并保留 environment 解析以对齐
企微判断),将两应用第一方代码里的 wx.getSystemInfoSync / wx.getSystemInfo
统一改为 getSystemInfoSync / getSystemInfo,消除基础库弃用告警:

- 各页面/组件读取 windowWidth/windowHeight/pixelRatio/SDKVersion 等字段
- storageApi / util / utils_wx 包装器改为回调式兼容接口
- NavigationBar 的 getSystemInfo().then 改同步调用,去掉异步时序
- 兼容层对旧基础库保留一次 wx.getSystemInfoSync 兜底(environment)

vendored 库(echarts / mp-html / sentry-miniapp)不动。
1 parent 34f40616
Showing 29 changed files with 362 additions and 117 deletions
// components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -34,39 +36,35 @@ Component({
},
init() {
/**
* 获取自定义导航栏信息
* 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/
wx.getSystemInfo().then(res => {
let {
fontSizeSetting,
statusBarHeight,
screenWidth
} = res
const {
height,
right,
width,
top
} = wx.getMenuButtonBoundingClientRect(),
currentPages = getCurrentPages(), {
showBack
} = this.data
if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true
})
let navigationBarHeight = height + ((top - statusBarHeight) * 2)
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width * 2)
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
const {
height,
right,
width,
top,
} = wx.getMenuButtonBoundingClientRect()
const currentPages = getCurrentPages()
const { showBack } = this.data
if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true
})
let navigationBarHeight = height + ((top - statusBarHeight) * 2)
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width * 2)
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
},
emit({
......
// packageEquity/pages/active/active.js
import { equityApi } from '~/api/api'
import USER from '~/api/usersApi/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({
/**
* 页面的初始数据
......@@ -109,7 +110,7 @@ Page({
},
onLoad: function (options) {
this.login()
let system = wx.getSystemInfoSync()
let system = getSystemInfoSync()
this.setData({
cHeight: system.windowHeight
})
......
import { equityApi } from '~/api/api'
import { isMember } from '~/utils/cache/storageApi'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({
/**
* 页面的初始数据
......@@ -16,7 +17,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let system = wx.getSystemInfoSync()
let system = getSystemInfoSync()
this.getAllMerchantList()
this.setData(
{
......
import { couponsApi, shopmallApi, ssoApi } from '~/api/api'
import USER from '~/api/usersApi/index'
import { defaultMerchantId } from '~/utils/request/environment'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({
data: {
freeDay: 0,
......@@ -110,7 +111,7 @@ Page({
})
},
onLoad(options) {
let system = wx.getSystemInfoSync()
let system = getSystemInfoSync()
const merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
let newMerchantId = merchantId || defaultMerchantId
......
import { commonApi, equityApi } from '~/api/api'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({
data: {
tempFilePath: '',
......@@ -34,7 +35,7 @@ Page({
let query = wx.createSelectorQuery().in(this); //获取自定义组件的SelectQuery对象
this.canvasCtx = wx.createCanvasContext('signature', that)
// 设置线的样式
let { windowWidth, windowHeight } = wx.getSystemInfoSync()
let { windowWidth, windowHeight } = getSystemInfoSync()
this.canvasCtx.setFillStyle("white");
this.canvasCtx.fillRect(0, 0, windowWidth, windowHeight);
this.canvasCtx.setLineCap("round");
......
// components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -33,24 +35,25 @@ Component({
},
init() {
/**
* 获取自定义导航栏信息
* 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/
wx.getSystemInfo().then(res => {
let { fontSizeSetting, statusBarHeight, screenWidth } = res
const { height, right, width, top } = wx.getMenuButtonBoundingClientRect()
let navigationBarHeight = height + (top - statusBarHeight) * 2 + 4 // 4
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
const { height, right, width, top } = wx.getMenuButtonBoundingClientRect()
let navigationBarHeight = height + (top - statusBarHeight) * 2 + 4 // 4
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
},
emit({ navigationBarHeight, statusBarHeight }) {
......
......@@ -2,6 +2,7 @@
import { imgUrlMixin } from '~/mixins/index'
import index_const from '~/pages/tab/storeAssistant/pages/index/index_const'
import Draw from '~/utils/Draw'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -20,7 +21,7 @@ Component({
wx.$api.showLoading('处理中')
val.boxImageHeight = 66
// 计算弹窗图片区域最大高度
let windowHeight = wx.getSystemInfoSync().windowHeight
let windowHeight = getSystemInfoSync().windowHeight
let res = {
height: windowHeight - 150
}
......
//index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from './u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
var uChartsInstance = {};
Component({
properties: {
......@@ -19,9 +20,9 @@ Component({
methods: {
setLine() {
//这里的第一个 750 对应 css .charts 的 width
const cWidth = 640 / 750 * wx.getSystemInfoSync().windowWidth;
const cWidth = 640 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height
const cHeight = 300 / 750 * wx.getSystemInfoSync().windowWidth;
const cHeight = 300 / 750 * getSystemInfoSync().windowWidth;
this.setData({
cWidth,
cHeight
......
// packageStoreAssistant/packageActivity/pages/pay/pay.js
import ActivityApi from '~/api/activityApi/index'
import wxqrcode from '~/utils/lib/wxqrcode'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
import {
centsToyuan,
accAdd
......@@ -234,7 +235,7 @@ Page({
// console.log(text)
let size = 0
try {
const info = wx.getSystemInfoSync()
const info = getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale
size = width
......
// packageStoreAssistant/packageEquityClaims/components/picture/picture.js
import { commonApi } from '~/api/api'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -80,7 +81,7 @@ Component({
// this.triggerEvent('upload', {url: 'https://img02.glsx.com.cn/weapp/resource/saas/scrm/assets/glsx/logo_collapse_new_common.png',type : 'png'});
// if(e) return
const {count} = this.data.configOptions
let sysInfo = wx.getSystemInfoSync()
let sysInfo = getSystemInfoSync()
let maxNum = sysInfo?.environment ? 9 : 20 // 企微打开的话最大是9张。如果count大于9 会无法上传有异常
let aleadyLength = 0
if (batchFlag) {
......
import MineApi from '~/api/mineApi/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({
/**
* 页面的初始数据
......@@ -70,7 +71,7 @@ Page({
pageSize,
merchantId
}).then(res => {
let windowWidth = wx.getSystemInfoSync().windowWidth
let windowWidth = getSystemInfoSync().windowWidth
let activityTitleViewWidth = windowWidth - ((windowWidth / 375) * (46 + 48 + 160 + 24)) / 2 // 活动title区域宽度
res.list &&
res.list.forEach((val, index) => {
......
import { IMG_URL } from "~/utils/constantData";
import { discoveryApi,shopmallApi } from "~/api/api";
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -95,7 +96,7 @@ Component({
}
});
const systemInfo = wx.getSystemInfoSync()
const systemInfo = getSystemInfoSync()
this.setData({
channelStyle,
list,
......
// pages/tab/storeAssistant/pages/index/components/clueManage/clueManage.js
import { imgUrlMixin } from '~/mixins/index'
import activityApi from '~/api/activityApi/index';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
behaviors: [imgUrlMixin],
......@@ -49,7 +50,7 @@ Component({
methods: {
computeBottom() {
try {
wx.getSystemInfo({
getSystemInfo({
success: (res) => {
const ratio = res.screenWidth / 750
const safeInsetBottom = res.safeArea ? (res.screenHeight - res.safeArea.bottom) : 0
......
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
// pages/tab/storeAssistant/pages/index/components/sopChart/sopChart.js
// import * as echarts from '../ec-canvas/echarts';
var uChartsInstance = {};
......@@ -33,9 +34,9 @@ Component({
methods: {
onReady() {
//这里的第一个 750 对应 css .charts 的 width
const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth;
const cWidth = 750 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height
const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth;
const cHeight = 500 / 750 * getSystemInfoSync().windowWidth;
this.setData({
cWidth: 320,
cHeight: 140
......
import { imgUrlMixin } from '~/mixins/index'
import USERAPI from "~/api/usersApi/index";
import activityApi from '~/api/activityApi/index';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
behaviors: [imgUrlMixin],
properties: {
......@@ -38,7 +39,7 @@ Component({
methods: {
computeBottom() {
try {
wx.getSystemInfo({
getSystemInfo({
success: (res) => {
const ratio = res.screenWidth / 750
const safeInsetBottom = res.safeArea ? (res.screenHeight - res.safeArea.bottom) : 0
......
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
import {
equityApi
} from '~/api/api'
......@@ -48,7 +49,7 @@ export function getNavigationBarTitleText() {
/** 存储设备信息 */
export function setSystem_info(that) {
let info = $Storage.get('system_info')
!info && wx.getSystemInfo({
!info && getSystemInfo({
success(res) {
// console.log(res)
$Storage.set('system_info', res)
......
/**
* @file 系统信息兼容层:合并微信新 API,替代已废弃的 wx.getSystemInfoSync / wx.getSystemInfo。
* 纯函数模块,不调 setData、不访问页面实例。
* 与 usedcar 的 utils/systemInfo.js 保持一致的实现。
*/
/** 测试专用:重置 legacy environment 缓存 */
export function __resetLegacyEnvironmentCacheForTest() {
legacyEnvironmentResolved = false
legacyEnvironmentCache = LEGACY_ENV_UNSET
}
/** @type {string|undefined|symbol} */
let legacyEnvironmentCache
/** 是否已解析过 legacy environment(含「无需 sync」的结论) */
let legacyEnvironmentResolved = false
const LEGACY_ENV_UNSET = Symbol('legacyEnvironmentUnset')
/**
* 旧版企微判断:优先新 API,仅在必要时调用一次原生 wx.getSystemInfoSync().environment
* @returns {string|undefined}
*/
function getLegacyEnvironment() {
if (legacyEnvironmentResolved) {
return legacyEnvironmentCache === LEGACY_ENV_UNSET ? undefined : legacyEnvironmentCache
}
legacyEnvironmentResolved = true
try {
const appBase = wx.getAppBaseInfo?.()
const host = appBase?.host
const hostEnv = typeof host === 'string' ? host : host?.env
if (hostEnv === 'wxwork') {
legacyEnvironmentCache = 'wxwork'
return legacyEnvironmentCache
}
if (typeof wx.qy !== 'undefined') {
legacyEnvironmentCache = 'wxwork'
return legacyEnvironmentCache
}
const legacyEnv = wx.getSystemInfoSync?.()?.environment
legacyEnvironmentCache = legacyEnv || LEGACY_ENV_UNSET
return legacyEnv
} catch (_) {
legacyEnvironmentCache = LEGACY_ENV_UNSET
return undefined
}
}
/**
* 解析企微运行环境,对齐旧版 getSystemInfoSync().environment
* 优先 legacy / host.env、wx.qy 兜底
* @param {string|{ env?: string }} [host]
* @returns {string}
*/
function resolveEnvironment(host) {
const legacyEnv = getLegacyEnvironment()
if (legacyEnv) return legacyEnv
const hostEnv = typeof host === 'string' ? host : host?.env
if (hostEnv === 'wxwork') return 'wxwork'
if (typeof wx.qy !== 'undefined') return 'wxwork'
return ''
}
/**
* 同步获取与旧版 getSystemInfoSync 兼容的系统信息对象
* @returns {WechatMiniprogram.SystemInfo}
*/
export function getSystemInfoSync() {
const deviceInfo = wx.getDeviceInfo()
const windowInfo = wx.getWindowInfo()
const appBaseInfo = wx.getAppBaseInfo()
return {
...deviceInfo,
...windowInfo,
...appBaseInfo,
environment: resolveEnvironment(appBaseInfo.host),
}
}
/**
* 登录端标识,对齐 loginControlList 后端约定:1 企微,0 微信
* 与旧版 accountItems / wxLogin 一致:优先读原生 wx.getSystemInfoSync().environment
* @returns {0|1}
*/
export function getLoginEnvName() {
const legacyEnv = getLegacyEnvironment()
if (legacyEnv) return 1
return getSystemInfoSync().environment ? 1 : 0
}
/**
* 异步获取系统信息,行为对齐旧版 wx.getSystemInfo
* @param {WechatMiniprogram.GetSystemInfoOption} [options]
*/
export function getSystemInfo(options = {}) {
try {
const res = getSystemInfoSync()
options.success?.(res)
} catch (err) {
options.fail?.(err)
} finally {
options.complete?.()
}
}
......@@ -4,6 +4,7 @@ import {
Storage
} from '~/utils/cache/storage'
import sopApi from '~/api/sopApi'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const $Storage = new Storage()
/**
* 日期格式化
......@@ -31,7 +32,7 @@ const isEmptyObj = (obj) => {
};
const setNavigationBarTitle = (title) => {
wx.getSystemInfo({
getSystemInfo({
success: (res) => {
// console.log('++++++++++++++', res);
// console.log('title length',title.length)
......
import $router from '../router/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/**
* 微信校验通知类工具封装
......@@ -98,7 +99,7 @@ const wxShowToast = (name, params) => {
/**获取设备信息 */
const getSystemInfo = callBack => {
wx.getSystemInfo({
getSystemInfo({
success(res) {
callBack(res)
},
......@@ -131,7 +132,7 @@ const isFullSucreen = isComponents => {
let {
navigationStyle
} = __wxConfig.page[key].window
wx.getSystemInfo({
getSystemInfo({
success(res) {
if (res.platform != 'android') {
let {
......
// components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
......@@ -34,39 +36,35 @@ Component({
},
init() {
/**
* 获取自定义导航栏信息
* 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/
wx.getSystemInfo().then(res => {
let {
fontSizeSetting,
statusBarHeight,
screenWidth
} = res
const {
height,
right,
width,
top
} = wx.getMenuButtonBoundingClientRect(),
currentPages = getCurrentPages(), {
showBack
} = this.data
if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true
})
let navigationBarHeight = height + ((top - statusBarHeight) * 2) + 4 // 4
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
const {
height,
right,
width,
top,
} = wx.getMenuButtonBoundingClientRect()
const currentPages = getCurrentPages()
const { showBack } = this.data
if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true
})
let navigationBarHeight = height + ((top - statusBarHeight) * 2) + 4 // 4
let navigationBarPadding = screenWidth - right
let navigationBarWidth = screenWidth - (navigationBarPadding * 2 + width) - width
this.setData({
statusBarHeight,
navigationBarHeight,
navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px;`
})
this.emit({
navigationBarHeight,
statusBarHeight
})
},
emit({
......
import WxCanvas from './wx-canvas';
import * as echarts from './echarts';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
let ctx;
......@@ -78,7 +79,7 @@ Component({
methods: {
init: function (callback) {
const version = wx.getSystemInfoSync().SDKVersion
const version = getSystemInfoSync().SDKVersion
const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0;
const forceUseOldCanvas = this.data.forceUseOldCanvas;
......@@ -115,7 +116,7 @@ console.log(this.data.isUseNewCanvas)
echarts.setCanvasCreator(() => {
return canvas;
});
// const canvasDpr = wx.getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
// const canvasDpr = getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
const canvasDpr = 1
var query = wx.createSelectorQuery().in(this);
query.select('.ec-canvas').boundingClientRect(res => {
......@@ -146,7 +147,7 @@ console.log(this.data.isUseNewCanvas)
const canvasNode = res[0].node
this.canvasNode = canvasNode
const canvasDpr = wx.getSystemInfoSync().pixelRatio
const canvasDpr = getSystemInfoSync().pixelRatio
const canvasWidth = res[0].width
const canvasHeight = res[0].height
......
//index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
var uChartsInstance = {};
Component({
properties: {
......@@ -33,10 +34,10 @@ Component({
isLabel
} = this.data
//这里的第一个 750 对应 css .charts 的 width
const cWidth = (isLabel?700:width) / 750 * wx.getSystemInfoSync().windowWidth;
const cWidth = (isLabel?700:width) / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height
const cHeight = width / 750 * wx.getSystemInfoSync().windowWidth;
const pixelRatio = wx.getSystemInfoSync().pixelRatio;
const cHeight = width / 750 * getSystemInfoSync().windowWidth;
const pixelRatio = getSystemInfoSync().pixelRatio;
this.setData({
cWidth,
cHeight,
......
//index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const view = require('../view.js')
var uChartsInstance = {};
......@@ -16,10 +17,10 @@ Component({
methods: {
getRatio() {
//这里的第一个 750 对应 css .charts 的 width
const cWidth = 700 / 750 * wx.getSystemInfoSync().windowWidth;
const cWidth = 700 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height
const cHeight = 480 / 750 * wx.getSystemInfoSync().windowWidth;
const pixelRatio = wx.getSystemInfoSync().pixelRatio;
const cHeight = 480 / 750 * getSystemInfoSync().windowWidth;
const pixelRatio = getSystemInfoSync().pixelRatio;
this.setData({
cWidth,
cHeight,
......
//index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const view = require('../view.js')
var uChartsInstance = {};
Component({
......@@ -14,9 +15,9 @@ Component({
methods: {
getRatio() {
//这里的第一个 750 对应 css .charts 的 width
const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth;
const cWidth = 750 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height
const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth;
const cHeight = 500 / 750 * getSystemInfoSync().windowWidth;
this.setData({
cWidth,
cHeight
......
// 实例化对象存储
import { Storage } from './storage'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const $Storage = new Storage()
// console.log($Storage)
/** */
......@@ -54,7 +55,7 @@ export function getNavigationBarTitleText() {
export function setSystem_info(that) {
let info = $Storage.get('system_info')
!info &&
wx.getSystemInfo({
getSystemInfo({
success(res) {
// console.log(res)
$Storage.set('system_info', res)
......
import { preReleaseAppId } from '~/config'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease']
const mockObj = {
test: 'https://oss-config.dev.glsx.com.cn/mock/63fd6c2034c4d918e2f4df4d/config',
......@@ -15,7 +16,7 @@ const mockObj = {
// const index = 1
const accountInfo = wx.getAccountInfoSync()
const systemInfo = wx.getSystemInfoSync()
const systemInfo = getSystemInfoSync()
// console.log(systemInfo);
// console.log(accountInfo.miniProgram.envVersion)
//手动控制体验版环境的请求 true就依据下面index false就默认为2
......
/**
* @file 系统信息兼容层:合并微信新 API,替代已废弃的 wx.getSystemInfoSync / wx.getSystemInfo。
* 纯函数模块,不调 setData、不访问页面实例。
* 与 usedcar 的 utils/systemInfo.js 保持一致的实现。
*/
/** 测试专用:重置 legacy environment 缓存 */
export function __resetLegacyEnvironmentCacheForTest() {
legacyEnvironmentResolved = false
legacyEnvironmentCache = LEGACY_ENV_UNSET
}
/** @type {string|undefined|symbol} */
let legacyEnvironmentCache
/** 是否已解析过 legacy environment(含「无需 sync」的结论) */
let legacyEnvironmentResolved = false
const LEGACY_ENV_UNSET = Symbol('legacyEnvironmentUnset')
/**
* 旧版企微判断:优先新 API,仅在必要时调用一次原生 wx.getSystemInfoSync().environment
* @returns {string|undefined}
*/
function getLegacyEnvironment() {
if (legacyEnvironmentResolved) {
return legacyEnvironmentCache === LEGACY_ENV_UNSET ? undefined : legacyEnvironmentCache
}
legacyEnvironmentResolved = true
try {
const appBase = wx.getAppBaseInfo?.()
const host = appBase?.host
const hostEnv = typeof host === 'string' ? host : host?.env
if (hostEnv === 'wxwork') {
legacyEnvironmentCache = 'wxwork'
return legacyEnvironmentCache
}
if (typeof wx.qy !== 'undefined') {
legacyEnvironmentCache = 'wxwork'
return legacyEnvironmentCache
}
const legacyEnv = wx.getSystemInfoSync?.()?.environment
legacyEnvironmentCache = legacyEnv || LEGACY_ENV_UNSET
return legacyEnv
} catch (_) {
legacyEnvironmentCache = LEGACY_ENV_UNSET
return undefined
}
}
/**
* 解析企微运行环境,对齐旧版 getSystemInfoSync().environment
* 优先 legacy / host.env、wx.qy 兜底
* @param {string|{ env?: string }} [host]
* @returns {string}
*/
function resolveEnvironment(host) {
const legacyEnv = getLegacyEnvironment()
if (legacyEnv) return legacyEnv
const hostEnv = typeof host === 'string' ? host : host?.env
if (hostEnv === 'wxwork') return 'wxwork'
if (typeof wx.qy !== 'undefined') return 'wxwork'
return ''
}
/**
* 同步获取与旧版 getSystemInfoSync 兼容的系统信息对象
* @returns {WechatMiniprogram.SystemInfo}
*/
export function getSystemInfoSync() {
const deviceInfo = wx.getDeviceInfo()
const windowInfo = wx.getWindowInfo()
const appBaseInfo = wx.getAppBaseInfo()
return {
...deviceInfo,
...windowInfo,
...appBaseInfo,
environment: resolveEnvironment(appBaseInfo.host),
}
}
/**
* 登录端标识,对齐 loginControlList 后端约定:1 企微,0 微信
* 与旧版 accountItems / wxLogin 一致:优先读原生 wx.getSystemInfoSync().environment
* @returns {0|1}
*/
export function getLoginEnvName() {
const legacyEnv = getLegacyEnvironment()
if (legacyEnv) return 1
return getSystemInfoSync().environment ? 1 : 0
}
/**
* 异步获取系统信息,行为对齐旧版 wx.getSystemInfo
* @param {WechatMiniprogram.GetSystemInfoOption} [options]
*/
export function getSystemInfo(options = {}) {
try {
const res = getSystemInfoSync()
options.success?.(res)
} catch (err) {
options.fail?.(err)
} finally {
options.complete?.()
}
}
......@@ -7,6 +7,7 @@ import { commonApi, equityApi } from "../api/api";
// equityApi
// } from '../api/api'
import $router from "../router/index";
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/**
* 日期格式化
......@@ -69,7 +70,7 @@ const isFullSucreen = (isComponents) => {
let val = false;
if (__wxConfig && __wxConfig.page && __wxConfig.page[key]) {
let { navigationStyle } = __wxConfig.page[key].window;
wx.getSystemInfo({
getSystemInfo({
success(res) {
if (res.platform != "android") {
let { statusBarHeight, screenHeight, windowHeight } = res;
......@@ -242,7 +243,7 @@ const deepClone = (target) => {
//设置标题
const setNavigationBarTitle = (title) =>{
wx.getSystemInfo({
getSystemInfo({
success: (res) => {
// console.log('++++++++++++++', res);
// console.log('title length',title.length)
......
import wxqrcode from '~/utils/lib/wxqrcode.js'
import $router from '../router/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/**
* 微信校验通知类工具封装
*/
......@@ -94,7 +95,7 @@ const wxShowToast = (name, params) => {
/**获取设备信息 */
const getSystemInfo = callBack => {
wx.getSystemInfo({
getSystemInfo({
success(res) {
callBack(res)
},
......@@ -179,7 +180,7 @@ const isFullSucreen = isComponents => {
let {
navigationStyle
} = __wxConfig.page[key].window
wx.getSystemInfo({
getSystemInfo({
success(res) {
if (res.platform != 'android') {
let {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!