123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- <template>
- <oa-scroll
- customClass="deviceDetails-container scroll-height"
- :isSticky="false"
- :refresherLoad="false"
- :refresherEnabled="false"
- :refresherEnabledTitle="false"
- :refresherDefaultStyle="'none'"
- :refresherThreshold="44"
- :refresherBackground="'#f5f6f7'"
- :data-theme="'theme-' + proxy.$settingStore.themeColor.name"
- >
- <template #default>
- <view class="header-area p15">
- <view class="header-area-top flex mb15">
- <view class="title"> {{ commonStore.deviceManageData.deviceName }} </view>
- <view class="status" :style="{ backgroundColor: commonStore.deviceManageData.deviceStatus == 1 ? '#16bf00' : 'red' }">
- {{ commonStore.deviceManageData.deviceStatus == 1 ? "在线" : "离线" }}
- </view>
- </view>
- <u-row class="header-area-center p0">
- <u-col span="9">
- <view class="header-area-center-item" v-for="data in listData" :key="data">
- <span class="title">{{ data.title }}:</span>
- <span class="value">{{ commonStore.deviceManageData[data.prop] ? commonStore.deviceManageData[data.prop] : "-" }}</span>
- </view>
- </u-col>
- <u-col span="3">
- <image style="width: 80px; height: 80px; display: flex; margin: auto 0 auto auto" :src="commonStore.deviceManageData.typeImg" mode="aspectFill"></image>
- </u-col>
- </u-row>
- </view>
- <view class="body-area">
- <!-- 分段器组件 -->
- <view class="subsection">
- <view class="subsection-item" v-for="(li, index) in tabs.list" :key="index" :class="{ active: index == tabs.value }" @click="tabPositionChange(index)">{{ li }}</view>
- </view>
- <view class="realTimeData-area flex plr15" v-if="tabs.value == 0">
- <view class="realTimeData-area-item" v-for="item in realTimeData" :key="item">
- <view class="title">{{ item.attributeName }}</view>
- <view class="value">
- <span v-if="item.attributeDict.length > 0">
- {{ Number.isFinite(item.value) ? proxy.$common.mapping("name", "value", item.value, item.attributeDict) : item.value ? item.value : "-" }}
- </span>
- <span v-else>
- {{ Number.isFinite(item.value) ? (Number.isInteger(item.value) ? item.value : item.value.toFixed(2)) : item.value ? item.value : "-" }}
- </span>
- <span style="color: #333; width: auto; font-size: 14px">{{ item.attributeUnit }} </span>
- </view>
- </view>
- </view>
- <view class="plr15" v-if="tabs.value == 1">
- <view class="flex" :style="{ color: proxy.$settingStore.themeColor.color }">
- <view class="ml10" style="margin-left: auto" @click="open">选择时间</view>
- <view class="ml10" @click="modalShow = true">筛选</view>
- </view>
- <chart :currentDateList="ecahrtsDate"></chart>
- </view>
- <view class="cotrol-area plr15" v-if="tabs.value == 2">
- <view class="cotrol-area-item p10 mb15" v-for="(item, index) in deviceCotrolData" :key="index">
- <view class="title flex" v-if="item.commandDict.length > 0 && item.commandName.indexOf('开关') != -1">
- <span style="margin: auto 0">{{ item.commandName }}</span>
- <span style="margin: auto 0 auto auto">
- <u-switch v-model="item.commandValue" :activeValue="1" :inactiveValue="0" size="20" @change="selectItem(item)"></u-switch>
- </span>
- </view>
- <u-select
- v-else-if="item.commandDict.length > 0 && item.commandName.indexOf('开关') == -1"
- v-model:current="item.commandValue"
- :label="item.commandName"
- :options="item.commandDict"
- keyName="value"
- labelName="name"
- @select="selectItem(item)"
- >
- <template #text>
- <view class="title">
- <span>{{ item.commandName }}</span>
- <span v-if="item.commandValue">({{ proxy.$common.mapping("name", "value", item.commandValue, item.commandDict) }})</span>
- </view>
- </template>
- </u-select>
- <view class="title" v-else>
- <view class="flex mb10">
- <span style="margin: auto 0"> {{ item.commandName }}</span>
- <span style="margin: auto 0 auto auto"> {{ item.commandValue }}</span>
- </view>
- <u-slider v-model="item.commandValue" :min="item.minimum" :max="item.maximum" :step="item.dataType == 4 ? 0.1 : 1" height="5px" @change="selectItem(item)"></u-slider>
- </view>
- </view>
- </view>
- </view>
- <u-modal :show="modalShow" @confirm="modalShow = false" @close="modalShow = false" :closeOnClickOverlay="true">
- <view class="slot-content">
- <u-checkbox-group
- v-model="checkbox.value"
- @change="
- (val) => {
- checkboxChange(val);
- }
- "
- :size="14"
- :activeColor="proxy.$settingStore.themeColor.color"
- >
- <u-checkbox class="mb10" v-for="option in checkbox.list" :key="option" :label="option.attributeName" :name="option.attributeCode"> </u-checkbox>
- </u-checkbox-group>
- </view>
- </u-modal>
- <uni-calendar ref="calendar" class="uni-calendar--hook" :clearDate="false" :insert="false" :lunar="false" :range="true" @confirm="calendarConfirm" />
- </template>
- </oa-scroll>
- </template>
- <script setup>
- /*----------------------------------依赖引入-----------------------------------*/
- import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
- import { ref, reactive, computed, getCurrentInstance, toRefs, inject, watch } from "vue";
- /*----------------------------------接口引入-----------------------------------*/
- import { dmpProductAttribute, historyMetrics, last, getList, control } from "@/api/business/fireIot/deviceManage.js";
- /*----------------------------------组件引入-----------------------------------*/
- import chart from "./chart.vue";
- /*----------------------------------store引入-----------------------------------*/
- import { useStores, commonStores } from "@/store/modules/index";
- /*----------------------------------公共方法引入-----------------------------------*/
- /*----------------------------------公共变量-----------------------------------*/
- const { proxy } = getCurrentInstance();
- const commonStore = commonStores();
- /*----------------------------------变量声明-----------------------------------*/
- const state = reactive({
- listData: [
- { title: "设备类型", prop: "productName" },
- { title: "设备编号", prop: "deviceId" },
- { title: "SIM卡号", prop: "simCode" },
- { title: "安装位置", prop: "installAddress" },
- { title: "添加时间", prop: "createdTime" },
- ],
- tabs: {
- list: ["实时数据", "历史数据", "指令操作"],
- value: 0,
- },
- metrics: [], //属性编号数据存储
- metricsValue: {}, //属性编号值数据存储
- realTimeData: [], //实时数据存储
- ecahrtsDate: [], //图表数据存储
- deviceCotrolData: [], //设备调试数据存储
- checkbox: {
- list: [], //复选框渲染数据存储
- value: [], //复选框值数据存储
- },
- });
- const { listData, tabs, metrics, metricsValue, realTimeData, ecahrtsDate, deviceCotrolData, checkbox } = toRefs(state);
- const modalShow = ref(false); //模态框显示隐藏
- const calendar = ref(null);
- const calendarStartTime = ref(proxy.$dayjs().format("YYYY-MM-DD")); //日历开始时间
- const calendarEndTime = ref(proxy.$dayjs().format("YYYY-MM-DD")); //日历结束时间
- const productId = ref(0); //产品id
- const deviceId = ref(0); //设备id
- /**
- * @初始化
- */
- function init() {
- state.metrics = [];
- state.realTimeData = [];
- state.checkbox.list = [];
- dmpProductAttribute({
- current: 1,
- size: 100,
- attributeName: "",
- productId: productId.value,
- deviceId: deviceId.value,
- }).then((requset) => {
- if (requset.status === "SUCCESS") {
- requset.data.records.forEach((item) => {
- item.attributeDict = item.attributeDict ? JSON.parse(item.attributeDict) : [];
- state.metrics.push(item.attributeCode.toLowerCase());
- state.realTimeData.push(item);
- state.checkbox.list.push({
- ...item,
- attributeCode: item.attributeCode.toLowerCase(),
- });
- });
- last({
- metrics: state.metrics,
- deviceuuid: [commonStore.deviceManageData.deviceUuid],
- }).then((requset) => {
- if (requset.status != "SUCCESS") return;
- if (requset.data.length <= 0) return;
- state.metricsValue = requset.data[0].metrics;
- Object.keys(state.metricsValue).forEach((key) => {
- state.realTimeData.forEach((el) => {
- if (el.attributeCode.toLowerCase() === key) {
- el.value = state.metricsValue[key];
- }
- });
- });
- });
- }
- });
- }
- function deviceControlData() {
- state.deviceCotrolData = [];
- getList({
- current: 1,
- size: 10,
- productCode: commonStore.deviceManageData.productCode,
- }).then((response) => {
- response.data.records.forEach((e) => {
- e.commandDict = e.commandDict ? JSON.parse(e.commandDict) : [];
- e.commandValue = state.metricsValue[e.commandCode.toLowerCase()];
- state.deviceCotrolData.push(e);
- });
- });
- }
- function selectItem(e) {
- proxy.$modal.loading("加载中");
- var params = {
- commandCode: e.commandCode,
- commandValue: e.commandValue,
- productCode: e.productCode,
- deviceUuid: commonStore.deviceManageData.deviceUuid,
- categoryType: commonStore.deviceManageData.categoryType,
- gatewayUuid: commonStore.deviceManageData.gatewayUuid,
- };
- control(params).then((res) => {
- init();
- proxy.$modal.closeLoading();
- proxy.$modal.msg(res.data.message);
- });
- }
- /**
- * @tabs切换change事件
- */
- function tabPositionChange(index) {
- state.tabs.value = index;
- }
- /**
- * @checkbox选中change事件
- */
- function checkboxChange(value) {
- state.checkbox.value = value;
- historyMetricsApi();
- }
- /**
- * @日历确认事件
- */
- function calendarConfirm(e) {
- calendarStartTime.value = e.range.before;
- calendarEndTime.value = e.range.after ? e.range.after : e.range.before;
- historyMetricsApi();
- }
- /**
- * @设备多属性历史数据请求
- * @api接口请求
- */
- function historyMetricsApi() {
- historyMetrics({
- startTime: calendarStartTime.value ? calendarStartTime.value + " 00:00:00" : calendarStartTime.value,
- endTime: calendarEndTime.value ? calendarEndTime.value + " 23:59:59" : calendarEndTime.value,
- deviceuuid: [commonStore.deviceManageData.deviceUuid],
- metrics: state.checkbox.value.length > 0 ? state.checkbox.value : state.metrics,
- }).then((requset) => {
- if (requset.status != "SUCCESS") return;
- if (requset.data.length <= 0) return;
- var metrics = requset.data[0].metrics;
- state.checkbox.list.forEach((el) => {
- metrics.forEach((e) => {
- if (el.attributeCode.toLowerCase() == e.metric) {
- e.attributeName = el.attributeName;
- }
- });
- });
- metrics.forEach((el) => {
- el.data = [];
- if (el.metricItems.length > 0) {
- el.metricItems.forEach((e) => {
- el.data.push([e.timestamp, e.value]);
- });
- }
- });
- state.ecahrtsDate = metrics;
- });
- }
- function open() {
- calendar.value.open();
- }
- onReady(() => {});
- onShow(() => {
- //设置导航栏颜色
- uni.setNavigationBarColor({
- frontColor: "#000000", //字体颜色
- backgroundColor: "#ffffff", //背景颜色
- });
- //调用系统主题颜色
- // proxy.$settingStore.systemThemeColor([1]);
- });
- onLoad((options) => {
- if ("deviceId" in options) {
- deviceId.value = options.deviceId;
- }
- if ("productId" in options) {
- productId.value = parseInt(options.productId);
- init();
- }
- });
- watch(
- () => state.tabs.value,
- (val) => {
- if (val == 2) {
- deviceControlData();
- }
- }
- );
- </script>
- <style lang="scss" scoped>
- .header-area {
- border-radius: 10px;
- background: linear-gradient(to bottom, #fafbff, #e7f3ff);
- &-top {
- justify-content: space-between;
- .title {
- font-size: 18px;
- color: #000;
- font-weight: 600;
- }
- .status {
- font-size: 15px;
- color: #ffffff;
- padding: 2px 10px;
- border-radius: 20px;
- line-height: 22px;
- }
- }
- &-center {
- width: 100%;
- text-align: left;
- font-size: 14px;
- color: rgba(0, 0, 0, 0.7);
- &-item {
- > span {
- display: inline-block;
- line-height: 25px;
- }
- .title,
- .value {
- padding: 0px 5px 0px 5px;
- }
- }
- }
- }
- .body-area {
- .realTimeData-area {
- flex-wrap: wrap;
- line-height: 30px;
- font-size: 16px;
- &-item {
- width: calc(50% - 7.5px);
- padding: 10px;
- margin-bottom: 10px;
- border-radius: 5px;
- box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);
- background-color: #ffffff;
- &:nth-child(2n -1) {
- margin-right: 15px;
- }
- .title {
- font-size: 14px;
- }
- .value {
- display: inline-block;
- color: #000;
- font-size: 16px;
- font-weight: 600;
- }
- }
- }
- .cotrol-area {
- &-item {
- border-radius: 5px;
- box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);
- .title {
- color: #000;
- font-weight: 600;
- font-size: 14px;
- }
- }
- }
- .subsection {
- display: flex;
- justify-content: center;
- margin: 15px 0;
- &-item {
- margin-right: 15px;
- &:last-child {
- margin-right: 0;
- }
- }
- .active {
- font-weight: 600;
- animation: colorChange 1s forwards;
- @keyframes colorChange {
- 0% {
- color: #666666;
- }
- 100% {
- color: #000;
- } /* 深色 */
- }
- }
- }
- }
- :deep() {
- .u-slider__show-value {
- margin: 10px 0px 10px 18px !important;
- }
- }
- uni-page-body {
- background-color: #fff;
- }
- .demo-layout {
- padding: 15px 10px;
- box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- }
- </style>
|