Files
app-govern/pages/index/index.vue

238 lines
8.5 KiB
Vue
Raw Normal View History

2023-01-11 16:33:13 +08:00
<template>
2023-02-20 14:19:28 +08:00
<Cn-page :loading="loading" noPadding>
2023-08-03 14:51:36 +08:00
<view slot="body" class="canneng-index">
2023-08-23 16:22:08 +08:00
<uni-nav-bar
2023-08-03 14:51:36 +08:00
rightWidth="300rpx"
leftWidth="300rpx"
dark
:fixed="true"
status-bar
2023-08-23 16:22:08 +08:00
background-color="#fff"
color="#111"
@clickRight="selectEngineering"
2023-08-03 14:51:36 +08:00
>
<template slot="left">
<text style="font-size: 32rpx; font-weight: 500">灿能物联</text>
</template>
<template slot="right">
2023-09-18 19:23:27 +08:00
<text class="hide-txt mr5" style="font-size: 28rpx"
>{{ select.engineeringName || emptyEngineeringName }}
2023-08-24 15:35:45 +08:00
</text>
<uni-icons type="bottom" size="16" color="#111" v-if="select.engineeringName"></uni-icons>
2023-08-03 14:51:36 +08:00
</template>
2023-08-23 16:22:08 +08:00
</uni-nav-bar>
2023-01-13 16:32:56 +08:00
<view class="index">
2023-02-09 08:50:01 +08:00
<!-- 运维 -->
2023-09-18 19:23:27 +08:00
<YunWei :devCount="devCount" v-if="userInfo.authorities === 'operation_manager'" />
2023-02-09 08:50:01 +08:00
<!-- 专职 -->
2023-09-18 19:23:27 +08:00
<ZhuanZhi :devCount="devCount" v-if="userInfo.authorities === 'market_user'" />
2023-02-09 08:50:01 +08:00
<!-- 工程 -->
2023-09-18 19:23:27 +08:00
<GongCheng :devCount="devCount" v-if="userInfo.authorities === 'engineering_user'" />
2023-02-09 08:50:01 +08:00
<!-- 主用户 -->
2023-09-18 19:23:27 +08:00
<ZhuYongHu :devCount="devCount" v-if="userInfo.authorities === 'app_vip_user'" />
2023-08-17 15:37:19 +08:00
<YouKe :devCount="devCount" v-if="userInfo.authorities === 'tourist'"></YouKe>
<template v-if="engineeringList.length">
<view class="canneng-index-title mt20">设备列表</view>
2023-09-18 19:23:27 +08:00
<Device ref="device" :store="store" />
2023-08-17 15:37:19 +08:00
</template>
2023-01-13 16:32:56 +08:00
</view>
2023-01-13 13:23:25 +08:00
</view>
2023-02-23 08:44:46 +08:00
</Cn-page>
2023-01-11 16:33:13 +08:00
</template>
<script>
2023-05-24 08:58:48 +08:00
import YunWei from './comp/indexYunWei.vue'
import GongCheng from './comp/indexGongCheng.vue'
import ZhuYongHu from './comp/indexZhuYongHu.vue'
import ZhuanZhi from './comp/indexZhuanZhi.vue'
import YouKe from './comp/indexYouKe.vue'
2023-07-03 20:29:24 +08:00
import Device from './comp/device.vue'
2023-04-04 08:47:19 +08:00
import list from '../../common/js/list'
2023-09-18 19:23:27 +08:00
import { getDevCount } from '../../common/api/device.js'
import { queryEngineering } from '@/common/api/engineering.js'
2023-08-03 14:51:36 +08:00
2023-01-13 13:23:25 +08:00
export default {
2023-04-04 08:47:19 +08:00
mixins: [list],
2023-02-09 08:50:01 +08:00
components: {
YunWei,
GongCheng,
ZhuYongHu,
2023-02-28 16:39:58 +08:00
ZhuanZhi,
2023-05-24 08:58:48 +08:00
YouKe,
2023-07-03 20:29:24 +08:00
Device,
2023-02-09 08:50:01 +08:00
},
2023-04-04 08:47:19 +08:00
data() {
2023-01-13 13:23:25 +08:00
return {
2023-07-03 20:29:24 +08:00
loading: false,
userInfo: {},
2023-07-06 14:24:03 +08:00
devCount: {},
2023-08-03 14:51:36 +08:00
select: {
engineeringName: '',
engineeringId: '',
},
engineeringList: [],
2023-09-18 19:23:27 +08:00
navTabHeight: 0,
2023-09-21 15:15:17 +08:00
timer: null,
2023-02-09 08:50:01 +08:00
}
},
2023-08-29 16:14:09 +08:00
computed: {
emptyEngineeringName() {
if (this.userInfo.authorities === 'tourist') {
return '创建工程'
} else if (this.userInfo.authorities === 'market_user') {
return '请联系管理员配置工程'
} else {
return '创建工程'
}
2023-09-18 19:23:27 +08:00
},
2023-08-29 16:14:09 +08:00
},
2023-01-13 13:23:25 +08:00
methods: {
2023-08-23 16:22:08 +08:00
selectEngineering() {
2023-08-24 15:35:45 +08:00
if (this.select.engineeringName) {
uni.navigateTo({
url: '/pages/home/selectEngineering',
})
} else {
2023-08-31 09:29:40 +08:00
if (this.userInfo.authorities === 'tourist') {
2023-08-29 16:14:09 +08:00
return uni.showToast({
title: '此功能仅对VIP用户开放',
icon: 'none',
})
2023-08-31 09:29:40 +08:00
} else if (this.userInfo.authorities === 'market_user') {
2023-08-29 16:14:09 +08:00
return uni.showToast({
title: '请联系管理员配置工程',
icon: 'none',
})
}
2023-08-24 15:35:45 +08:00
uni.navigateTo({
url: '/pages/engineering/new',
})
}
2023-08-10 09:18:17 +08:00
},
2023-08-03 14:51:36 +08:00
async init() {
let engineering = uni.getStorageSync('engineering')
let res = await queryEngineering()
this.engineeringList = res.data
2023-08-23 16:22:08 +08:00
uni.setStorageSync('engineeringList', this.engineeringList)
2023-08-03 14:51:36 +08:00
if (this.engineeringList.length === 0) {
2023-08-17 15:37:19 +08:00
console.log('没有工程')
2023-08-17 09:24:59 +08:00
uni.removeStorageSync(this.$cacheKey.engineering)
2023-08-29 16:14:09 +08:00
this.select.engineeringName = ''
this.select.engineeringId = ''
2023-08-17 15:37:19 +08:00
this.projectList = []
2023-08-03 14:51:36 +08:00
} else {
2023-08-17 15:37:19 +08:00
if (!engineering) {
2023-08-03 14:51:36 +08:00
uni.setStorageSync('engineering', res.data[0])
this.select.engineeringName = res.data[0].name
this.select.engineeringId = res.data[0].id
} else {
2023-08-17 15:37:19 +08:00
if (this.engineeringList.findIndex((item) => item.id === engineering.id) === -1) {
uni.setStorageSync('engineering', res.data[0])
this.select.engineeringName = res.data[0].name
this.select.engineeringId = res.data[0].id
} else {
this.select.engineeringName = engineering.name
this.select.engineeringId = engineering.id
}
2023-08-03 14:51:36 +08:00
}
2023-08-17 15:37:19 +08:00
this.store.params.engineerId = this.select.engineeringId
this.getDevCount()
2023-08-23 16:22:08 +08:00
console.log(this.$refs.device, 'this.$refs.device')
this.$nextTick(() => {
this.$refs.device && this.$refs.device.init()
})
2023-08-03 14:51:36 +08:00
}
2023-08-17 15:37:19 +08:00
},
getDevCount() {
2023-09-21 15:15:17 +08:00
if (!this.select.engineeringId) return
2023-08-03 14:51:36 +08:00
getDevCount(this.select.engineeringId).then((res) => {
2023-08-17 15:37:19 +08:00
// Object.assign(this.devCount, res.data)
2023-08-03 14:51:36 +08:00
this.devCount = res.data
2023-08-11 11:03:31 +08:00
this.devCount.currentOffLineDevs.forEach((item) => {
item.runStatus = 1
})
this.devCount.offLineDevs.forEach((item) => {
item.runStatus = 1
})
2023-08-17 09:24:59 +08:00
this.devCount.engineeringListLength = this.engineeringList.length
2023-09-21 15:15:17 +08:00
uni.setStorage({
key: this.$cacheKey.messageCount,
data: this.devCount,
})
let messagePage =
this.devCount.runCount +
this.devCount.eventCount +
this.devCount.alarmCount +
this.devCount.harmonicCount
let minePage = this.devCount.harmonicCount
uni.setTabBarBadge({
index: 1,
text: messagePage ? messagePage + '' : '',
})
uni.setTabBarBadge({
index: 2,
text: minePage ? minePage + '' : '',
})
2023-08-03 14:51:36 +08:00
})
},
2023-01-13 16:32:56 +08:00
},
2023-05-24 08:58:48 +08:00
onLoad() {
2023-09-18 19:23:27 +08:00
if (!uni.getStorageSync(this.$cacheKey.access_token)) {
uni.reLaunch({
url: '/pages/user/login',
})
}
2023-07-03 20:29:24 +08:00
this.store = this.DataSource('/cs-device-boot/EquipmentDelivery/queryEquipmentByProject')
2023-08-23 16:22:08 +08:00
// #ifdef APP-PLUS
setTimeout(() => {
// 获取nav高度
2023-09-18 19:23:27 +08:00
uni.createSelectorQuery()
.select('.uni-navbar')
.boundingClientRect((rect) => {
this.navTabHeight = rect.height
console.log('calc(100vh - ' + this.navTabHeight + ')')
})
.exec()
2023-08-23 16:22:08 +08:00
}, 1000)
// #endif
2023-02-09 08:50:01 +08:00
},
2023-04-04 08:47:19 +08:00
onShow() {
2023-02-23 08:44:46 +08:00
this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
2023-08-31 09:29:40 +08:00
let access_token = uni.getStorageSync(this.$cacheKey.access_token)
if (!access_token) {
uni.reLaunch({
2023-09-18 19:23:27 +08:00
url: `/pages/user/login`,
2023-08-31 09:29:40 +08:00
})
} else {
this.init()
2023-09-21 15:15:17 +08:00
this.timer = setInterval(this.getDevCount, 10000) // 定时请求
2023-02-23 08:44:46 +08:00
}
2023-05-24 08:58:48 +08:00
},
2023-09-21 15:15:17 +08:00
onHide() {
clearInterval(this.timer)
}
2023-01-13 13:23:25 +08:00
}
2023-01-11 16:33:13 +08:00
</script>
2023-01-13 16:32:56 +08:00
<style lang="scss">
2023-08-23 16:22:08 +08:00
.popup-content {
background: #fff;
}
2023-01-13 16:32:56 +08:00
.index {
2023-08-03 14:51:36 +08:00
padding: 20rpx 0 0;
}
2023-08-17 15:37:19 +08:00
2023-08-03 14:51:36 +08:00
.canneng-index-title {
padding: 0 20rpx;
font-size: 28rpx;
font-weight: 500;
2023-01-13 13:23:25 +08:00
}
2023-08-17 15:37:19 +08:00
2023-02-07 17:59:54 +08:00
/deep/ .uni-card {
background: $uni-theme-white;
}
2023-08-03 14:51:36 +08:00
/deep/ .uni-drawer__content {
width: 100vw !important;
}
2023-01-11 16:33:13 +08:00
</style>