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 311 additions and 66 deletions
// components/navigationBar/navigationBar.js // components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -34,23 +36,20 @@ Component({ ...@@ -34,23 +36,20 @@ Component({
}, },
init() { init() {
/** /**
* 获取自定义导航栏信息 * 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/ */
wx.getSystemInfo().then(res => { const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
let {
fontSizeSetting,
statusBarHeight,
screenWidth
} = res
const { const {
height, height,
right, right,
width, width,
top top,
} = wx.getMenuButtonBoundingClientRect(), } = wx.getMenuButtonBoundingClientRect()
currentPages = getCurrentPages(), { const currentPages = getCurrentPages()
showBack const { showBack } = this.data
} = this.data
if (showBack && currentPages.length > 1) this.setData({ if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true SHOWBACK: true
}) })
...@@ -67,7 +66,6 @@ Component({ ...@@ -67,7 +66,6 @@ Component({
navigationBarHeight, navigationBarHeight,
statusBarHeight statusBarHeight
}) })
})
}, },
emit({ emit({
navigationBarHeight, navigationBarHeight,
......
// packageEquity/pages/active/active.js // packageEquity/pages/active/active.js
import { equityApi } from '~/api/api' import { equityApi } from '~/api/api'
import USER from '~/api/usersApi/index' import USER from '~/api/usersApi/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -109,7 +110,7 @@ Page({ ...@@ -109,7 +110,7 @@ Page({
}, },
onLoad: function (options) { onLoad: function (options) {
this.login() this.login()
let system = wx.getSystemInfoSync() let system = getSystemInfoSync()
this.setData({ this.setData({
cHeight: system.windowHeight cHeight: system.windowHeight
}) })
......
import { equityApi } from '~/api/api' import { equityApi } from '~/api/api'
import { isMember } from '~/utils/cache/storageApi' import { isMember } from '~/utils/cache/storageApi'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -16,7 +17,7 @@ Page({ ...@@ -16,7 +17,7 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
let system = wx.getSystemInfoSync() let system = getSystemInfoSync()
this.getAllMerchantList() this.getAllMerchantList()
this.setData( this.setData(
{ {
......
import { couponsApi, shopmallApi, ssoApi } from '~/api/api' import { couponsApi, shopmallApi, ssoApi } from '~/api/api'
import USER from '~/api/usersApi/index' import USER from '~/api/usersApi/index'
import { defaultMerchantId } from '~/utils/request/environment' import { defaultMerchantId } from '~/utils/request/environment'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({ Page({
data: { data: {
freeDay: 0, freeDay: 0,
...@@ -110,7 +111,7 @@ Page({ ...@@ -110,7 +111,7 @@ Page({
}) })
}, },
onLoad(options) { onLoad(options) {
let system = wx.getSystemInfoSync() let system = getSystemInfoSync()
const merchantId = wx.$storage.get('srcm_shopmall_merchant_id') const merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
let newMerchantId = merchantId || defaultMerchantId let newMerchantId = merchantId || defaultMerchantId
......
import { commonApi, equityApi } from '~/api/api' import { commonApi, equityApi } from '~/api/api'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({ Page({
data: { data: {
tempFilePath: '', tempFilePath: '',
...@@ -34,7 +35,7 @@ Page({ ...@@ -34,7 +35,7 @@ Page({
let query = wx.createSelectorQuery().in(this); //获取自定义组件的SelectQuery对象 let query = wx.createSelectorQuery().in(this); //获取自定义组件的SelectQuery对象
this.canvasCtx = wx.createCanvasContext('signature', that) this.canvasCtx = wx.createCanvasContext('signature', that)
// 设置线的样式 // 设置线的样式
let { windowWidth, windowHeight } = wx.getSystemInfoSync() let { windowWidth, windowHeight } = getSystemInfoSync()
this.canvasCtx.setFillStyle("white"); this.canvasCtx.setFillStyle("white");
this.canvasCtx.fillRect(0, 0, windowWidth, windowHeight); this.canvasCtx.fillRect(0, 0, windowWidth, windowHeight);
this.canvasCtx.setLineCap("round"); this.canvasCtx.setLineCap("round");
......
// components/navigationBar/navigationBar.js // components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -33,10 +35,12 @@ Component({ ...@@ -33,10 +35,12 @@ Component({
}, },
init() { init() {
/** /**
* 获取自定义导航栏信息 * 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/ */
wx.getSystemInfo().then(res => { const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
let { fontSizeSetting, statusBarHeight, screenWidth } = res
const { height, right, width, top } = wx.getMenuButtonBoundingClientRect() const { height, right, width, top } = wx.getMenuButtonBoundingClientRect()
let navigationBarHeight = height + (top - statusBarHeight) * 2 + 4 // 4 let navigationBarHeight = height + (top - statusBarHeight) * 2 + 4 // 4
let navigationBarPadding = screenWidth - right let navigationBarPadding = screenWidth - right
...@@ -51,7 +55,6 @@ Component({ ...@@ -51,7 +55,6 @@ Component({
navigationBarHeight, navigationBarHeight,
statusBarHeight statusBarHeight
}) })
})
}, },
emit({ navigationBarHeight, statusBarHeight }) { emit({ navigationBarHeight, statusBarHeight }) {
let navHeight = navigationBarHeight + statusBarHeight let navHeight = navigationBarHeight + statusBarHeight
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { imgUrlMixin } from '~/mixins/index' import { imgUrlMixin } from '~/mixins/index'
import index_const from '~/pages/tab/storeAssistant/pages/index/index_const' import index_const from '~/pages/tab/storeAssistant/pages/index/index_const'
import Draw from '~/utils/Draw' import Draw from '~/utils/Draw'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -20,7 +21,7 @@ Component({ ...@@ -20,7 +21,7 @@ Component({
wx.$api.showLoading('处理中') wx.$api.showLoading('处理中')
val.boxImageHeight = 66 val.boxImageHeight = 66
// 计算弹窗图片区域最大高度 // 计算弹窗图片区域最大高度
let windowHeight = wx.getSystemInfoSync().windowHeight let windowHeight = getSystemInfoSync().windowHeight
let res = { let res = {
height: windowHeight - 150 height: windowHeight - 150
} }
......
//index.js //index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本! //注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from './u-charts/u-charts.js'; import uCharts from './u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
var uChartsInstance = {}; var uChartsInstance = {};
Component({ Component({
properties: { properties: {
...@@ -19,9 +20,9 @@ Component({ ...@@ -19,9 +20,9 @@ Component({
methods: { methods: {
setLine() { setLine() {
//这里的第一个 750 对应 css .charts 的 width //这里的第一个 750 对应 css .charts 的 width
const cWidth = 640 / 750 * wx.getSystemInfoSync().windowWidth; const cWidth = 640 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height //这里的 500 对应 css .charts 的 height
const cHeight = 300 / 750 * wx.getSystemInfoSync().windowWidth; const cHeight = 300 / 750 * getSystemInfoSync().windowWidth;
this.setData({ this.setData({
cWidth, cWidth,
cHeight cHeight
......
// packageStoreAssistant/packageActivity/pages/pay/pay.js // packageStoreAssistant/packageActivity/pages/pay/pay.js
import ActivityApi from '~/api/activityApi/index' import ActivityApi from '~/api/activityApi/index'
import wxqrcode from '~/utils/lib/wxqrcode' import wxqrcode from '~/utils/lib/wxqrcode'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
import { import {
centsToyuan, centsToyuan,
accAdd accAdd
...@@ -234,7 +235,7 @@ Page({ ...@@ -234,7 +235,7 @@ Page({
// console.log(text) // console.log(text)
let size = 0 let size = 0
try { try {
const info = wx.getSystemInfoSync() const info = getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽 let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale let width = 300 * scale
size = width size = width
......
// packageStoreAssistant/packageEquityClaims/components/picture/picture.js // packageStoreAssistant/packageEquityClaims/components/picture/picture.js
import { commonApi } from '~/api/api' import { commonApi } from '~/api/api'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -80,7 +81,7 @@ 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'}); // 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 // if(e) return
const {count} = this.data.configOptions const {count} = this.data.configOptions
let sysInfo = wx.getSystemInfoSync() let sysInfo = getSystemInfoSync()
let maxNum = sysInfo?.environment ? 9 : 20 // 企微打开的话最大是9张。如果count大于9 会无法上传有异常 let maxNum = sysInfo?.environment ? 9 : 20 // 企微打开的话最大是9张。如果count大于9 会无法上传有异常
let aleadyLength = 0 let aleadyLength = 0
if (batchFlag) { if (batchFlag) {
......
import MineApi from '~/api/mineApi/index' import MineApi from '~/api/mineApi/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -70,7 +71,7 @@ Page({ ...@@ -70,7 +71,7 @@ Page({
pageSize, pageSize,
merchantId merchantId
}).then(res => { }).then(res => {
let windowWidth = wx.getSystemInfoSync().windowWidth let windowWidth = getSystemInfoSync().windowWidth
let activityTitleViewWidth = windowWidth - ((windowWidth / 375) * (46 + 48 + 160 + 24)) / 2 // 活动title区域宽度 let activityTitleViewWidth = windowWidth - ((windowWidth / 375) * (46 + 48 + 160 + 24)) / 2 // 活动title区域宽度
res.list && res.list &&
res.list.forEach((val, index) => { res.list.forEach((val, index) => {
......
import { IMG_URL } from "~/utils/constantData"; import { IMG_URL } from "~/utils/constantData";
import { discoveryApi,shopmallApi } from "~/api/api"; import { discoveryApi,shopmallApi } from "~/api/api";
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -95,7 +96,7 @@ Component({ ...@@ -95,7 +96,7 @@ Component({
} }
}); });
const systemInfo = wx.getSystemInfoSync() const systemInfo = getSystemInfoSync()
this.setData({ this.setData({
channelStyle, channelStyle,
list, list,
......
// pages/tab/storeAssistant/pages/index/components/clueManage/clueManage.js // pages/tab/storeAssistant/pages/index/components/clueManage/clueManage.js
import { imgUrlMixin } from '~/mixins/index' import { imgUrlMixin } from '~/mixins/index'
import activityApi from '~/api/activityApi/index'; import activityApi from '~/api/activityApi/index';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({ Component({
behaviors: [imgUrlMixin], behaviors: [imgUrlMixin],
...@@ -49,7 +50,7 @@ Component({ ...@@ -49,7 +50,7 @@ Component({
methods: { methods: {
computeBottom() { computeBottom() {
try { try {
wx.getSystemInfo({ getSystemInfo({
success: (res) => { success: (res) => {
const ratio = res.screenWidth / 750 const ratio = res.screenWidth / 750
const safeInsetBottom = res.safeArea ? (res.screenHeight - res.safeArea.bottom) : 0 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 // pages/tab/storeAssistant/pages/index/components/sopChart/sopChart.js
// import * as echarts from '../ec-canvas/echarts'; // import * as echarts from '../ec-canvas/echarts';
var uChartsInstance = {}; var uChartsInstance = {};
...@@ -33,9 +34,9 @@ Component({ ...@@ -33,9 +34,9 @@ Component({
methods: { methods: {
onReady() { onReady() {
//这里的第一个 750 对应 css .charts 的 width //这里的第一个 750 对应 css .charts 的 width
const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth; const cWidth = 750 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height //这里的 500 对应 css .charts 的 height
const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth; const cHeight = 500 / 750 * getSystemInfoSync().windowWidth;
this.setData({ this.setData({
cWidth: 320, cWidth: 320,
cHeight: 140 cHeight: 140
......
import { imgUrlMixin } from '~/mixins/index' import { imgUrlMixin } from '~/mixins/index'
import USERAPI from "~/api/usersApi/index"; import USERAPI from "~/api/usersApi/index";
import activityApi from '~/api/activityApi/index'; import activityApi from '~/api/activityApi/index';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({ Component({
behaviors: [imgUrlMixin], behaviors: [imgUrlMixin],
properties: { properties: {
...@@ -38,7 +39,7 @@ Component({ ...@@ -38,7 +39,7 @@ Component({
methods: { methods: {
computeBottom() { computeBottom() {
try { try {
wx.getSystemInfo({ getSystemInfo({
success: (res) => { success: (res) => {
const ratio = res.screenWidth / 750 const ratio = res.screenWidth / 750
const safeInsetBottom = res.safeArea ? (res.screenHeight - res.safeArea.bottom) : 0 const safeInsetBottom = res.safeArea ? (res.screenHeight - res.safeArea.bottom) : 0
......
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
import { import {
equityApi equityApi
} from '~/api/api' } from '~/api/api'
...@@ -48,7 +49,7 @@ export function getNavigationBarTitleText() { ...@@ -48,7 +49,7 @@ export function getNavigationBarTitleText() {
/** 存储设备信息 */ /** 存储设备信息 */
export function setSystem_info(that) { export function setSystem_info(that) {
let info = $Storage.get('system_info') let info = $Storage.get('system_info')
!info && wx.getSystemInfo({ !info && getSystemInfo({
success(res) { success(res) {
// console.log(res) // console.log(res)
$Storage.set('system_info', 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 { ...@@ -4,6 +4,7 @@ import {
Storage Storage
} from '~/utils/cache/storage' } from '~/utils/cache/storage'
import sopApi from '~/api/sopApi' import sopApi from '~/api/sopApi'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const $Storage = new Storage() const $Storage = new Storage()
/** /**
* 日期格式化 * 日期格式化
...@@ -31,7 +32,7 @@ const isEmptyObj = (obj) => { ...@@ -31,7 +32,7 @@ const isEmptyObj = (obj) => {
}; };
const setNavigationBarTitle = (title) => { const setNavigationBarTitle = (title) => {
wx.getSystemInfo({ getSystemInfo({
success: (res) => { success: (res) => {
// console.log('++++++++++++++', res); // console.log('++++++++++++++', res);
// console.log('title length',title.length) // console.log('title length',title.length)
......
import $router from '../router/index' import $router from '../router/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/** /**
* 微信校验通知类工具封装 * 微信校验通知类工具封装
...@@ -98,7 +99,7 @@ const wxShowToast = (name, params) => { ...@@ -98,7 +99,7 @@ const wxShowToast = (name, params) => {
/**获取设备信息 */ /**获取设备信息 */
const getSystemInfo = callBack => { const getSystemInfo = callBack => {
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
callBack(res) callBack(res)
}, },
...@@ -131,7 +132,7 @@ const isFullSucreen = isComponents => { ...@@ -131,7 +132,7 @@ const isFullSucreen = isComponents => {
let { let {
navigationStyle navigationStyle
} = __wxConfig.page[key].window } = __wxConfig.page[key].window
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
if (res.platform != 'android') { if (res.platform != 'android') {
let { let {
......
// components/navigationBar/navigationBar.js // components/navigationBar/navigationBar.js
import { getSystemInfoSync } from '~/utils/systemInfo'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -34,23 +36,20 @@ Component({ ...@@ -34,23 +36,20 @@ Component({
}, },
init() { init() {
/** /**
* 获取自定义导航栏信息 * 获取自定义导航栏信息。
* 基础库 2.20.1+ 起 getSystemInfo 已废弃,按字段拆分到新接口:
* statusBarHeight / screenWidth → getWindowInfo
* fontSizeSetting → getAppBaseInfo
*/ */
wx.getSystemInfo().then(res => { const { fontSizeSetting, statusBarHeight, screenWidth } = getSystemInfoSync()
let {
fontSizeSetting,
statusBarHeight,
screenWidth
} = res
const { const {
height, height,
right, right,
width, width,
top top,
} = wx.getMenuButtonBoundingClientRect(), } = wx.getMenuButtonBoundingClientRect()
currentPages = getCurrentPages(), { const currentPages = getCurrentPages()
showBack const { showBack } = this.data
} = this.data
if (showBack && currentPages.length > 1) this.setData({ if (showBack && currentPages.length > 1) this.setData({
SHOWBACK: true SHOWBACK: true
}) })
...@@ -67,7 +66,6 @@ Component({ ...@@ -67,7 +66,6 @@ Component({
navigationBarHeight, navigationBarHeight,
statusBarHeight statusBarHeight
}) })
})
}, },
emit({ emit({
navigationBarHeight, navigationBarHeight,
......
import WxCanvas from './wx-canvas'; import WxCanvas from './wx-canvas';
import * as echarts from './echarts'; import * as echarts from './echarts';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
let ctx; let ctx;
...@@ -78,7 +79,7 @@ Component({ ...@@ -78,7 +79,7 @@ Component({
methods: { methods: {
init: function (callback) { init: function (callback) {
const version = wx.getSystemInfoSync().SDKVersion const version = getSystemInfoSync().SDKVersion
const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0; const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0;
const forceUseOldCanvas = this.data.forceUseOldCanvas; const forceUseOldCanvas = this.data.forceUseOldCanvas;
...@@ -115,7 +116,7 @@ console.log(this.data.isUseNewCanvas) ...@@ -115,7 +116,7 @@ console.log(this.data.isUseNewCanvas)
echarts.setCanvasCreator(() => { echarts.setCanvasCreator(() => {
return canvas; return canvas;
}); });
// const canvasDpr = wx.getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr // const canvasDpr = getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
const canvasDpr = 1 const canvasDpr = 1
var query = wx.createSelectorQuery().in(this); var query = wx.createSelectorQuery().in(this);
query.select('.ec-canvas').boundingClientRect(res => { query.select('.ec-canvas').boundingClientRect(res => {
...@@ -146,7 +147,7 @@ console.log(this.data.isUseNewCanvas) ...@@ -146,7 +147,7 @@ console.log(this.data.isUseNewCanvas)
const canvasNode = res[0].node const canvasNode = res[0].node
this.canvasNode = canvasNode this.canvasNode = canvasNode
const canvasDpr = wx.getSystemInfoSync().pixelRatio const canvasDpr = getSystemInfoSync().pixelRatio
const canvasWidth = res[0].width const canvasWidth = res[0].width
const canvasHeight = res[0].height const canvasHeight = res[0].height
......
//index.js //index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本! //注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js'; import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
var uChartsInstance = {}; var uChartsInstance = {};
Component({ Component({
properties: { properties: {
...@@ -33,10 +34,10 @@ Component({ ...@@ -33,10 +34,10 @@ Component({
isLabel isLabel
} = this.data } = this.data
//这里的第一个 750 对应 css .charts 的 width //这里的第一个 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 //这里的 500 对应 css .charts 的 height
const cHeight = width / 750 * wx.getSystemInfoSync().windowWidth; const cHeight = width / 750 * getSystemInfoSync().windowWidth;
const pixelRatio = wx.getSystemInfoSync().pixelRatio; const pixelRatio = getSystemInfoSync().pixelRatio;
this.setData({ this.setData({
cWidth, cWidth,
cHeight, cHeight,
......
//index.js //index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本! //注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js'; import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const view = require('../view.js') const view = require('../view.js')
var uChartsInstance = {}; var uChartsInstance = {};
...@@ -16,10 +17,10 @@ Component({ ...@@ -16,10 +17,10 @@ Component({
methods: { methods: {
getRatio() { getRatio() {
//这里的第一个 750 对应 css .charts 的 width //这里的第一个 750 对应 css .charts 的 width
const cWidth = 700 / 750 * wx.getSystemInfoSync().windowWidth; const cWidth = 700 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height //这里的 500 对应 css .charts 的 height
const cHeight = 480 / 750 * wx.getSystemInfoSync().windowWidth; const cHeight = 480 / 750 * getSystemInfoSync().windowWidth;
const pixelRatio = wx.getSystemInfoSync().pixelRatio; const pixelRatio = getSystemInfoSync().pixelRatio;
this.setData({ this.setData({
cWidth, cWidth,
cHeight, cHeight,
......
//index.js //index.js
//注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本! //注意!基础库【2.9.0】起支持 2d 模式,如不显示请检查基础库版本!
import uCharts from '../../../../../utils/u-charts/u-charts.js'; import uCharts from '../../../../../utils/u-charts/u-charts.js';
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const view = require('../view.js') const view = require('../view.js')
var uChartsInstance = {}; var uChartsInstance = {};
Component({ Component({
...@@ -14,9 +15,9 @@ Component({ ...@@ -14,9 +15,9 @@ Component({
methods: { methods: {
getRatio() { getRatio() {
//这里的第一个 750 对应 css .charts 的 width //这里的第一个 750 对应 css .charts 的 width
const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth; const cWidth = 750 / 750 * getSystemInfoSync().windowWidth;
//这里的 500 对应 css .charts 的 height //这里的 500 对应 css .charts 的 height
const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth; const cHeight = 500 / 750 * getSystemInfoSync().windowWidth;
this.setData({ this.setData({
cWidth, cWidth,
cHeight cHeight
......
// 实例化对象存储 // 实例化对象存储
import { Storage } from './storage' import { Storage } from './storage'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const $Storage = new Storage() const $Storage = new Storage()
// console.log($Storage) // console.log($Storage)
/** */ /** */
...@@ -54,7 +55,7 @@ export function getNavigationBarTitleText() { ...@@ -54,7 +55,7 @@ export function getNavigationBarTitleText() {
export function setSystem_info(that) { export function setSystem_info(that) {
let info = $Storage.get('system_info') let info = $Storage.get('system_info')
!info && !info &&
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
// console.log(res) // console.log(res)
$Storage.set('system_info', res) $Storage.set('system_info', res)
......
import { preReleaseAppId } from '~/config' import { preReleaseAppId } from '~/config'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease'] const target = ['ip', 'dev', 'uat', 'prod', 'preRelease']
const mockObj = { const mockObj = {
test: 'https://oss-config.dev.glsx.com.cn/mock/63fd6c2034c4d918e2f4df4d/config', test: 'https://oss-config.dev.glsx.com.cn/mock/63fd6c2034c4d918e2f4df4d/config',
...@@ -15,7 +16,7 @@ const mockObj = { ...@@ -15,7 +16,7 @@ const mockObj = {
// const index = 1 // const index = 1
const accountInfo = wx.getAccountInfoSync() const accountInfo = wx.getAccountInfoSync()
const systemInfo = wx.getSystemInfoSync() const systemInfo = getSystemInfoSync()
// console.log(systemInfo); // console.log(systemInfo);
// console.log(accountInfo.miniProgram.envVersion) // console.log(accountInfo.miniProgram.envVersion)
//手动控制体验版环境的请求 true就依据下面index false就默认为2 //手动控制体验版环境的请求 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"; ...@@ -7,6 +7,7 @@ import { commonApi, equityApi } from "../api/api";
// equityApi // equityApi
// } from '../api/api' // } from '../api/api'
import $router from "../router/index"; import $router from "../router/index";
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/** /**
* 日期格式化 * 日期格式化
...@@ -69,7 +70,7 @@ const isFullSucreen = (isComponents) => { ...@@ -69,7 +70,7 @@ const isFullSucreen = (isComponents) => {
let val = false; let val = false;
if (__wxConfig && __wxConfig.page && __wxConfig.page[key]) { if (__wxConfig && __wxConfig.page && __wxConfig.page[key]) {
let { navigationStyle } = __wxConfig.page[key].window; let { navigationStyle } = __wxConfig.page[key].window;
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
if (res.platform != "android") { if (res.platform != "android") {
let { statusBarHeight, screenHeight, windowHeight } = res; let { statusBarHeight, screenHeight, windowHeight } = res;
...@@ -242,7 +243,7 @@ const deepClone = (target) => { ...@@ -242,7 +243,7 @@ const deepClone = (target) => {
//设置标题 //设置标题
const setNavigationBarTitle = (title) =>{ const setNavigationBarTitle = (title) =>{
wx.getSystemInfo({ getSystemInfo({
success: (res) => { success: (res) => {
// console.log('++++++++++++++', res); // console.log('++++++++++++++', res);
// console.log('title length',title.length) // console.log('title length',title.length)
......
import wxqrcode from '~/utils/lib/wxqrcode.js' import wxqrcode from '~/utils/lib/wxqrcode.js'
import $router from '../router/index' import $router from '../router/index'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
/** /**
* 微信校验通知类工具封装 * 微信校验通知类工具封装
*/ */
...@@ -94,7 +95,7 @@ const wxShowToast = (name, params) => { ...@@ -94,7 +95,7 @@ const wxShowToast = (name, params) => {
/**获取设备信息 */ /**获取设备信息 */
const getSystemInfo = callBack => { const getSystemInfo = callBack => {
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
callBack(res) callBack(res)
}, },
...@@ -179,7 +180,7 @@ const isFullSucreen = isComponents => { ...@@ -179,7 +180,7 @@ const isFullSucreen = isComponents => {
let { let {
navigationStyle navigationStyle
} = __wxConfig.page[key].window } = __wxConfig.page[key].window
wx.getSystemInfo({ getSystemInfo({
success(res) { success(res) {
if (res.platform != 'android') { if (res.platform != 'android') {
let { let {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!