Commit 2e70546b authored by xinzhedeai's avatar xinzhedeai

add :权限变量值公共提取,逻辑判断代码修改。工具js加载时序问题优化处理。去除无用js引用。

parent 3a47b3f6
body { [v-cloak] {
letter-spacing: 0.02rem; display: none;
} }
.page_wrapper { .page_wrapper {
...@@ -16,6 +16,7 @@ body { ...@@ -16,6 +16,7 @@ body {
} }
body { body {
letter-spacing: 0.02rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #f5f5f5; background-color: #f5f5f5;
} }
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>商户检查页面</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>高区安全“码”上查监管平台-首页</title>
<meta name="viewport" <meta name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0, viewprot-fit:cover" /> content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0, viewprot-fit:cover" />
<title>高区安全“码”上查监管平台-首页</title>
<link rel="stylesheet" href="home.css" /> <link rel="stylesheet" href="home.css" />
<style>
[v-cloak] {
display: none;
}
</style>
<!-- 在 includeHead.js 之后添加环境判断 --> <!-- 在 includeHead.js 之后添加环境判断 -->
<script src="./sdk/includeHead.js"></script> <script src="./sdk/includeHead.js"></script>
</head>
<body>
<!-- 获取授权用户信息 本地token等操作 --> <!-- 获取授权用户信息 本地token等操作 -->
<script> <script>
if (window.env === 'pro') { // 监听 includeHead.js 加载完成事件
document.write('<script type="text/javascript" src="sdk/jssdk2/index.js"><\/script>') document.querySelector('script[src="./sdk/includeHead.js"]').onload = function() {
} // includeHead.js 加载完成后,动态加载 home.js
const homeScript = document.createElement('script');
homeScript.type = 'text/javascript';
homeScript.src = './home.js';
document.body.appendChild(homeScript);
};
</script> </script>
<script type="text/javascript" src="./home.js"></script> </head>
<body>
<div id="app" class="page_wrapper" v-cloak> <div id="app" class="page_wrapper" v-cloak>
<!-- 原有内容(数据加载完成后显示) --> <!-- 原有内容(数据加载完成后显示) -->
<div v-show="!isLoading"> <div v-show="!isLoading">
......
var VUE = null var VUE = null
window.onload = function () { window.onload = function() {
// 在页面加载完成后执行 // const currentDate = gemhoUtil.getTargetDateYM()
// 执行你的代码 VUE = new Vue({
const currentDate = gemhoUtil.getTargetDateYM() el: '#app',
VUE = new Vue({ data() {
el: '#app', return {
data() { isLoading: true, // 新增:加载状态标记
return { showPopup4completionDate: false, // 控制日期选择器弹窗的显示与隐藏
isLoading: true, // 新增:加载状态标记 showOrg: false, //是否显示组织
showPopup4completionDate: false, showShop: false, //是否显示店铺
// 控制日期选择器弹窗的显示与隐藏 // 存储选择的日期
showPicker: false, selectedDate: '', // new Date(currentDate), // '', // gemhoUtil.formatDate(new Date(value)),
// 存储选择的日期 //显示的日期
selectedDate: new Date(currentDate), // '', // gemhoUtil.formatDate(new Date(value)), showDate: '', // currentDate,
//显示的日期 // 日期选择的最小范围,这里设置为当前日期的前 10 年
showDate: currentDate, minDate: new Date(new Date().getFullYear() - 10, 0),
// 日期选择的最小范围,这里设置为当前日期的前 10 年 // 日期选择的最大范围,这里设置为当前日期的后 10 年
minDate: new Date(new Date().getFullYear() - 10, 0), // maxDate: new Date(new Date().getFullYear() + 10, 11),
// 日期选择的最大范围,这里设置为当前日期的后 10 年 maxDate: new Date(),
// maxDate: new Date(new Date().getFullYear() + 10, 11), userInfo: {
maxDate: new Date(), userType: '', // 登录用户type
userInfo: { userId: '1', // 登录用户id
userType: '', // 登录用户type userName: '', // 登录用户name
userId: '1', // 登录用户id deptId: '1', // 登录用户部门id
userName: '', // 登录用户name deptName: '', // 登录用户部门name
deptId: '1', // 登录用户部门id safeLevel: '0', //0:绿、1:黄、2:红
deptName: '', // 登录用户部门name role: '',
safeLevel: '0', //0:绿、1:黄、2:红 roleName: '',
role: '', },
roleName: '', // 初始化为空数组,等待接口数据填充
}, userData: {
showOrg: false, //是否显示组织 checkCount: 0, //检查数
showShop: false, //是否显示店铺 checkSelfCount: 0, //自查数
hiddenCount: 0, //隐患数
hiddenNoReCount: 0, //未整改数
},
accessType: 'manage', // 访问类型 shop商家 saoma 扫码 manage 管理
// 修改默认菜单结构为最小化配置
menuList: [],
remindStatistic: []
}
},
mounted() {
this.init()
},
methods: {
async init() {
// 在组件挂载后执行
await this.getUserInfo();
await this.getStatisticData();
this.isLoading = false; // 数据加载完成后关闭加载状态
},
getRemindStatistic() {
http2.post({
serviceId: API_KEY_MAP['no-page']['id'],
interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
reqParams: {
sign: 23, // 商户首页统计
},
},
(res) => {
if (!res) {
// 中台返回为undefined 重新请求
setTimeout(() => {
this.getRemindStatistic()
}, 0)
return
}
if (res) {
var result = JSON.parse(res)
this.remindStatistic = result.data
}
}
)
},
scanCode(toData) { // 有菜单地址则是跳转页面,没有则是扫码操作
if (toData) {
let param = {
accessType: this.accessType,
merId: this.userInfo.merId || '',
unitName: this.userInfo.unitName,
smallPlaceTypeName: this.userInfo.smallPlaceTypeName,
}
if (gemhoUtil.isShop()) {
param = {
...param,
accessType: 'shop',
}
if (toData == 'check_info') {
param = {
...param,
accessType: 'shop',
flag: 'ADD',
pageName: '../home',
}
}
}
let url = gemhoUtil.setParameter(`src/_${toData}.html`, param)
gemhoUtil.navigatePage(url, '跳转中...')
} else {
lightAppJssdk.device.scan({
success: function(data) {
// 获取到data为二维码的url路径,从这里取请求参数,商户id,在下面跳转本地系统路径
// alert('扫码成功'+JSON.stringify(data))
const strUrl = new URL(data);
const param = {
merId: strUrl.searchParams.get('merId'),
accessType: strUrl.searchParams.get('accessType')
};
if (param.merId == null || param.merId == '') {
alert('请扫描正确的商家二维码')
return
} else {
let url = gemhoUtil.setParameter(`./src/_shanghu_home.html`,
param)
gemhoUtil.navigatePage(url, '跳转中...')
}
},
fail: function(data) {
//错误返回
alert('扫码失败')
},
})
}
},
getUserInfo() {
return new Promise((resolve) => {
http2.post({
serviceId: API_KEY_MAP['no-page']['id'],
interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
reqParams: {
sign: 9,
},
},
(res) => {
if (res) {
var result = JSON.parse(res)
if (result.code !== 200 && result.data == null) {
console.log('getUserInfo=>code200datanull')
return
}
this.userInfo = {
userType: result.data.roleDeptNameVo
.userType, // 登录用户type
userId: '1', // 登录用户id
userName: '张三', // 登录用户name
deptId: '1', // 登录用户部门id
safeLevel: result.data.merchantInfoNumVo
?.safeLevel, //0:绿、1:黄、2:红
deptName: result.data.roleDeptNameVo
.deptName, // 登录用户部门name
businessAddress: result.data.merchantInfoNumVo
?.businessAddress, //
smallPlaceTypeName: result.data.merchantInfoNumVo
?.smallPlaceTypeName, //
unitName: result.data.merchantInfoNumVo?.unitName, //
role: 'dudao',
roleName: result.data.roleDeptNameVo?.roleName,
merId: result.data.merchantInfoNumVo?.id, //
}
gemhoUtil.setCookie('userType', this.userInfo.userType)
if (gemhoUtil.isShop()) { // 2025年5月14日新增消费者逻辑
this.showOrg = false //是否显示组织
this.showShop = true //是否显示店铺
this.getRemindStatistic() // 2025年6月9日 新增珊瑚提醒
// 修改默认菜单结构为最小化配置 } else {
menuList: [], this.showOrg = true //是否显示组织
// 初始化为空数组,等待接口数据填充 this.showShop = false //是否显示店铺
userData: { }
checkCount: 0, //检查数
checkSelfCount: 0, //自查数
hiddenCount: 0, //隐患数
hiddenNoReCount: 0, //未整改数
},
accessType: 'manage', // 访问类型 shop商家 saoma 扫码 manage 管理
remindStatistic: []
}
},
mounted() {
// 在组件挂载后执行
// 调用你的方法
this.init()
},
computed: {},
methods: {
getRemindStatistic() {
http2.post(
{
serviceId: API_KEY_MAP['no-page']['id'],
interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
reqParams: {
sign: 23, // 商户首页统计
},
},
(res) => {
if (!res) {
// 中台返回为undefined 重新请求
setTimeout(() => {
this.getRemindStatistic()
}, 0)
return
}
if (res) {
var result = JSON.parse(res)
this.remindStatistic = result.data
}
}
)
},
openDebug() { // 双击开启debugg模式,再次双击则关闭
console.log('开启关闭debug')
if (localStorage.getItem('debug') == 'Y') {
localStorage.setItem('debug', 'N')
} else {
localStorage.setItem('debug', 'Y')
}
},
scanCode(toData) {
if (!toData) {
lightAppJssdk.device.scan({
success: function (data) {
// 获取到data为二维码的url路径,从这里取请求参数,商户id,在下面跳转本地系统路径
// alert('扫码成功'+JSON.stringify(data))
const strUrl = new URL(data);
const param = {
merId: strUrl.searchParams.get('merId'),
accessType: strUrl.searchParams.get('accessType')
};
if (param.merId == null || param.merId == '') {
alert('请扫描正确的商家二维码')
return
} else {
let url = gemhoUtil.setParameter(`./src/_shanghu_home.html`, param)
gemhoUtil.navigatePage(url, '跳转中...')
}
}, console.log('菜单', result.data.modules)
fail: function (data) { // 生成最终菜单列表
//错误返回 this.menuList = result.data.modules
alert('扫码失败') resolve();
}, }
}) })
} else { });
// if (this.userInfo.userType === 'shop' && toData === 'checkrecord') { },
// toData = 'checkrecord' // 获取用户数据的方法
// } else { getStatisticData() {
// toData = 'shanghu_list' return new Promise((resolve) => {
// } http2.post({
let param = { serviceId: API_KEY_MAP['no-page']['id'],
accessType: this.accessType, interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
merId: this.userInfo.merId || '', interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
unitName: this.userInfo.unitName, reqParams: {
smallPlaceTypeName: this.userInfo.smallPlaceTypeName, sign: 6,
} date: this.selectedDate,
if (this.userInfo.userType === 'shop') { merId: gemhoUtil.getParameter('merId') || '',
param = { },
...param, },
accessType: 'shop', (res) => {
} if (res) {
if (toData == 'check_info') { var result = JSON.parse(res)
param = { console.log('用户Data', result)
...param, this.userData = result.data
resolve();
}
}
)
});
},
showPopup() {
this['showPopup4completionDate'] = true
},
confirm4completionDate(value) {
this.selectedDate = gemhoUtil.getTargetDateYMByPara(value)
this.showDate = gemhoUtil.getTargetDateYMByPara(value)
this.showPopup4completionDate = false
this.getStatisticData()
},
accessType: 'shop', // 格式化日期显示的函数,根据需要自定义
flag: 'ADD', needData(type, val) {
pageName: '../home', if (type === 'year') {
} return `${val}`
} } else if (type === 'month') {
} return `${val}`
let url = gemhoUtil.setParameter(`src/_${toData}.html`, param) }
gemhoUtil.navigatePage(url, '跳转中...') return val
// gemhoUtil.navigatePage(`src/_${toData}.html`) },
} // 取消选择日期时的回调函数
}, onCancel() {
navTo(type) { // 消息统计跳转 this.showPicker = false
const param = { },
type, openDebug() { // 双击开启debugg模式,再次双击则关闭
merId: this.userInfo.merId console.log('开启关闭debug')
}; if (localStorage.getItem('debug') == 'Y') {
let url = gemhoUtil.setParameter(`./src/_yh_check.html`, param) localStorage.setItem('debug', 'N')
gemhoUtil.navigatePage(url, '跳转中...') } else {
}, localStorage.setItem('debug', 'Y')
gotoPage(stringifyUrl) { }
let url = gemhoUtil.setParameter(`src/_${stringifyUrl}.html`) },
gemhoUtil.navigatePage(url, '跳转中...') navTo(type) { // 消息统计跳转
}, const param = {
async init() { type,
// 在组件挂载后执行 merId: this.userInfo.merId
await this.getUserInfo(); };
await this.getStatisticData(); let url = gemhoUtil.setParameter(`./src/_yh_check.html`, param)
this.isLoading = false; // 数据加载完成后关闭加载状态 gemhoUtil.navigatePage(url, '跳转中...')
}, },
showPopup() { gotoPage(stringifyUrl) {
this['showPopup4completionDate'] = true let url = gemhoUtil.setParameter(`src/_${stringifyUrl}.html`)
}, gemhoUtil.navigatePage(url, '跳转中...')
confirm4completionDate(value) { },
this.selectedDate = gemhoUtil.getTargetDateYMByPara(value) },
this.showDate = gemhoUtil.getTargetDateYMByPara(value) //过滤器
this.showPopup4completionDate = false filters: {
this.getStatisticData() //格式化日期显示的函数,根据需要自定义
}, formatterData(val) {
if (!val) return ''
const [year, month] = val.split('-')
return `${year}${month}月`
},
},
// 格式化日期显示的函数,根据需要自定义 })
needData(type, val) { }
if (type === 'year') { \ No newline at end of file
return `${val}`
} else if (type === 'month') {
return `${val}`
}
return val
},
// 取消选择日期时的回调函数
onCancel() {
this.showPicker = false
},
getUserInfo() {
return new Promise((resolve) => {
http2.post({
serviceId: API_KEY_MAP['no-page']['id'],
interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
reqParams: {
sign: 9,
},
},
(res) => {
if (res) {
var result = JSON.parse(res)
if (result.code !== 200 && result.data == null) {
console.log('getUserInfo=>code200datanull')
return
}
this.userInfo = {
userType: result.data.roleDeptNameVo.userType, // 登录用户type
userId: '1', // 登录用户id
userName: '张三', // 登录用户name
deptId: '1', // 登录用户部门id
safeLevel: result.data.merchantInfoNumVo?.safeLevel, //0:绿、1:黄、2:红
deptName: result.data.roleDeptNameVo.deptName, // 登录用户部门name
businessAddress:
result.data.merchantInfoNumVo?.businessAddress, //
smallPlaceTypeName:
result.data.merchantInfoNumVo?.smallPlaceTypeName, //
unitName: result.data.merchantInfoNumVo?.unitName, //
role: 'dudao',
roleName: result.data.roleDeptNameVo?.roleName,
merId: result.data.merchantInfoNumVo?.id, //
}
gemhoUtil.setCookie('userType', this.userInfo.userType)
if (this.userInfo.userType === 'shop') { // 2025年5月14日新增消费者逻辑
this.showOrg = false //是否显示组织
this.showShop = true //是否显示店铺
this.getRemindStatistic() // 2025年6月9日 新增珊瑚提醒
} else if (['admin', 'common', 'industry', 'street', 'wgy'].includes(this.userInfo.userType)) {
this.showOrg = true //是否显示组织
this.showShop = false //是否显示店铺
}
console.log('菜单', result.data.modules)
// 生成最终菜单列表
this.menuList = result.data.modules
resolve();
}
})
});
},
// 获取用户数据的方法
getStatisticData() {
return new Promise((resolve) => {
http2.post({
serviceId: API_KEY_MAP['no-page']['id'],
interfacePublicKey: API_KEY_MAP['no-page']['publicKey'],
interfacePrivateKey: API_KEY_MAP['no-page']['privateKey'],
reqParams: {
sign: 6,
date: this.selectedDate,
merId: gemhoUtil.getParameter('merId')|| '',
},
},
(res) => {
if (res) {
var result = JSON.parse(res)
console.log('用户Data')
this.userData = result.data
resolve();
}
}
)
});
}
},
//过滤器
filters: {
//格式化日期显示的函数,根据需要自定义
formatterData(val) {
if (!val) return ''
const [year, month] = val.split('-')
return `${year}${month}月`
},
},
})
}
// ['admin', 'common', 'industry', 'street', 'wgy']
var AUTH = {
WGY: 'wgy', // 网格员
SHOP: 'shop', // 商户
CONSUMERS: 'consumers', // 消费者
}
var gemhoUtil = window.gemhoUtil || {} var gemhoUtil = window.gemhoUtil || {}
gemhoUtil.isWgy = function () {
return gemhoUtil.getCookie('userType') == AUTH.WGY
}
gemhoUtil.isShop = function () {
return gemhoUtil.getCookie('userType') === AUTH.SHOP
}
gemhoUtil.isConsumers = function () {
return gemhoUtil.getCookie('userType') == AUTH.CONSUMERS
}
gemhoUtil.formatDate = function (date, type) { gemhoUtil.formatDate = function (date, type) {
var ymd = `${date.getFullYear()}-${ var ymd = `${date.getFullYear()}-${
(date.getMonth() + 1 > 9 ? '' : '0') + (date.getMonth() + 1) (date.getMonth() + 1 > 9 ? '' : '0') + (date.getMonth() + 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment