detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <div class="page page-full">
  3. <div class="content">
  4. <div class="cont_box">
  5. <div class="title">产品:{{ detail.name }}</div>
  6. <div class="pro-status"><span :class="developer_status == 1 ? 'on' : 'off'"></span>{{ developer_status == 1
  7. ? '已发布' : '未发布' }}</div>
  8. <div class="pro-option" @click="CkOption" v-auth="'startOrStop'"> {{ developer_status == 1 ? '停用' : '启用' }}
  9. </div>
  10. </div>
  11. </div>
  12. <el-tabs v-model="activeName" style="padding: 0 20px;" @tab-click="handleClick">
  13. <el-tab-pane label="产品信息" name="1">
  14. <div class="pro-box">
  15. <div class="protitle">产品信息</div>
  16. <el-button type="" :icon="Edit" class="buttonedit" v-auth="'edit'" @click="onOpenEditDic(detail)">编辑</el-button>
  17. </div>
  18. <el-descriptions class="margin-top" :column="3" border>
  19. <el-descriptions-item label="产品标识">{{ detail.key }}</el-descriptions-item>
  20. <el-descriptions-item label="产品分类">{{ detail.categoryName }}</el-descriptions-item>
  21. <el-descriptions-item label="设备类型">{{ detail.deviceType }}</el-descriptions-item>
  22. <el-descriptions-item label="产品图片">
  23. <el-image style="width: 80px; height: 80px" :src="detail.icon" :previewSrcList="[detail.icon]" fit="contain">
  24. <template #error>
  25. <div class="image-slot">
  26. <ele-Picture style="width: 30px;" />
  27. 加载失败
  28. </div>
  29. </template>
  30. </el-image>
  31. </el-descriptions-item>
  32. <el-descriptions-item label="消息协议">{{ detail.messageProtocol }}</el-descriptions-item>
  33. <el-descriptions-item label="接入方式">{{ detail.transportProtocol }}</el-descriptions-item>
  34. <el-descriptions-item label="描述">{{ detail.desc }}</el-descriptions-item>
  35. </el-descriptions>
  36. </el-tab-pane>
  37. <el-tab-pane label="物模型" name="2">
  38. <el-tabs type="border-card" v-model="activetab" @tab-click="wuhandleClick">
  39. <el-tab-pane label="属性定义" name="attr">
  40. <div class="wu-title">
  41. <div class="title">属性定义</div>
  42. <div><el-button size="small" type="primary" v-auth="'edit'" @click="onOpenEditAttr()">添加</el-button>
  43. </div>
  44. </div>
  45. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'attr'">
  46. <el-table-column label="属性标识" align="center" prop="key" />
  47. <el-table-column label="属性名称" prop="name" show-overflow-tooltip />
  48. <el-table-column prop="valueType" label="数据类型" width="100" align="center">
  49. <template #default="scope">
  50. <span>{{ scope.row.valueType.type }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="decimals" label="精度" width="60" align="center">
  54. <template #default="scope">
  55. <span>{{ scope.row.valueType.decimals }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column prop="unit" label="单位" width="60" align="center">
  59. <template #default="scope">
  60. <span>{{ scope.row.valueType.unit }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column prop="accessMode" label="是否只读" width="120" align="center">
  64. <template #default="scope">
  65. <el-tag type="info" size="small" v-if="scope.row.accessMode">只读</el-tag>
  66. <el-tag type="success" size="small" v-else>读写</el-tag>
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="说明" prop="desc" show-overflow-tooltip />
  70. <el-table-column label="操作" width="300" align="center" fixed="right">
  71. <template #default="scope">
  72. <el-button size="small" text type="warning" v-auth="'edit'" @click="onEditAttr(scope.row)">修改</el-button>
  73. <el-button size="small" text type="danger" v-auth="'del'" @click="onRowDel(scope.row.key, 'attr')">删除</el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. </el-tab-pane>
  78. <el-tab-pane label="功能定义" name="fun">
  79. <div class="wu-title">
  80. <div class="title">功能定义</div>
  81. <div><el-button size="small" type="primary" v-auth="'add'" @click="onOpenEditFun()">添加</el-button>
  82. </div>
  83. </div>
  84. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'fun'">
  85. <el-table-column label="功能标识" align="center" prop="key" />
  86. <el-table-column label="名称" prop="name" show-overflow-tooltip />
  87. <el-table-column label="描述" prop="desc" show-overflow-tooltip />
  88. <el-table-column label="操作" width="300" align="center" fixed="right">
  89. <template #default="scope">
  90. <el-button size="small" text type="warning" v-auth="'edit'" @click="onEditFun(scope.row)">修改</el-button>
  91. <el-button size="small" text type="danger" v-auth="'del'" @click="onRowDel(scope.row.key, 'fun')">删除</el-button>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. </el-tab-pane>
  96. <el-tab-pane label="事件定义" name="event">
  97. <div class="wu-title">
  98. <div class="title">事件定义</div>
  99. <div>
  100. <el-button size="small" type="primary" v-auth="'add'" @click="onOpenEditEvent()">添加</el-button>
  101. </div>
  102. </div>
  103. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'event'">
  104. <el-table-column label="事件标识" align="center" prop="key" />
  105. <el-table-column label="名称" prop="name" show-overflow-tooltip />
  106. <el-table-column prop="level" label="事件级别" width="120" align="center">
  107. <template #default="scope">
  108. <el-tag type="primary" size="small" v-if="scope.row.level == 0">普通</el-tag>
  109. <el-tag type="warning" size="small" v-if="scope.row.level == 1">警告</el-tag>
  110. <el-tag type="danger" size="small" v-if="scope.row.level == 2">紧急</el-tag>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="描述" prop="desc" show-overflow-tooltip />
  114. <el-table-column label="操作" width="300" align="center" fixed="right">
  115. <template #default="scope">
  116. <el-button size="small" text type="warning" v-auth="'edit'" @click="onEditEvent(scope.row)">修改</el-button>
  117. <el-button size="small" text type="danger" v-auth="'del'" @click="onRowDel(scope.row.key, 'event')">删除</el-button>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. </el-tab-pane>
  122. <el-tab-pane label="标签定义" name="tab">
  123. <div class="wu-title">
  124. <div class="title">标签定义</div>
  125. <div><el-button size="small" type="primary" v-auth="'add'" @click="onOpenEditTab()">添加</el-button>
  126. </div>
  127. </div>
  128. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'tab'">
  129. <el-table-column label="属性标识" align="center" prop="key" />
  130. <el-table-column label="属性名称" prop="name" show-overflow-tooltip />
  131. <el-table-column prop="valueType" label="数据类型" width="120" align="center">
  132. <template #default="scope">
  133. <span>{{ scope.row.valueType.type }}</span>
  134. </template>
  135. </el-table-column>
  136. <el-table-column prop="accessMode" label="是否只读" width="120" align="center">
  137. <template #default="scope">
  138. <el-tag type="info" size="small" v-if="scope.row.accessMode">只读</el-tag>
  139. <el-tag type="success" size="small" v-else>读写</el-tag>
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="描述" prop="desc" show-overflow-tooltip />
  143. <el-table-column label="操作" width="300" align="center" fixed="right">
  144. <template #default="scope">
  145. <el-button size="small" text type="warning" v-auth="'edit'" @click="onEditTag(scope.row)">修改</el-button>
  146. <el-button size="small" text type="danger" v-auth="'del'" @click="onRowDel(scope.row.key, 'tab')">删除</el-button>
  147. </template>
  148. </el-table-column>
  149. </el-table>
  150. </el-tab-pane>
  151. </el-tabs>
  152. <div class="import">
  153. <div class="row_bet">
  154. <el-upload accept="json" :show-file-list="false" :limit="1" :data="{ key: detail.key }" :headers="headers" :action="uploadUrl" :on-success="updateImg">
  155. <el-button size="small">
  156. <el-icon> <ele-Upload /> </el-icon>
  157. 导入物模型
  158. </el-button>
  159. </el-upload>
  160. <el-button size="small" type="default" class="ml10" @click="onRowExport()">
  161. <el-icon>
  162. <ele-Download />
  163. </el-icon>
  164. 导出物模型
  165. </el-button>
  166. </div>
  167. </div>
  168. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getList()" />
  169. </el-tab-pane>
  170. <el-tab-pane label="设备接入" name="3">
  171. <deviceIn></deviceIn>
  172. </el-tab-pane>
  173. <el-tab-pane label="数据解析" name="4" lazy>
  174. <dataParse v-if="activeName === '4'" :script="detail.scriptInfo" @updateScript="updateScript">
  175. </dataParse>
  176. </el-tab-pane>
  177. </el-tabs>
  178. <EditDic ref="editDicRef" @typeList="typeList" />
  179. <EditAttr ref="editAttrRef" @typeList="getproperty" />
  180. <EditFun ref="editFunRef" @typeList="getfunction" />
  181. <EditEvent ref="editEventRef" @typeList="getevent" />
  182. <EditTab ref="editTabRef" @typeList="gettab" />
  183. </div>
  184. </template>
  185. <script lang="ts">
  186. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  187. import { Edit } from '@element-plus/icons-vue';
  188. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  189. import downloadFile from '/@/utils/download';
  190. import getOrigin from '/@/utils/origin';
  191. import EditDic from './component/editPro.vue';
  192. import deviceIn from './component/deviceIn.vue';
  193. import dataParse from './component/dataParse.vue';
  194. import EditAttr from './component/editAttr.vue';
  195. import EditFun from './component/editFun.vue';
  196. import EditEvent from './component/editEvent.vue';
  197. import EditTab from './component/editTab.vue';
  198. import { useRoute } from 'vue-router';
  199. import api from '/@/api/device';
  200. interface TableDataState {
  201. ids: number[];
  202. detail: any;
  203. tableData: {
  204. data: [];
  205. total: number;
  206. loading: boolean;
  207. param: {
  208. pageNum: number;
  209. pageSize: number;
  210. name: string;
  211. deviceType: string;
  212. status: string;
  213. dateRange: string[];
  214. };
  215. };
  216. }
  217. export default defineComponent({
  218. name: 'deviceEditPro',
  219. components: { EditDic, EditAttr, EditFun, EditEvent, EditTab, deviceIn, dataParse },
  220. setup(prop, context) {
  221. const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + "/product/tsl/import");
  222. const headers = {
  223. Authorization: 'Bearer ' + localStorage.token,
  224. };
  225. const route = useRoute();
  226. const editDicRef = ref();
  227. const editAttrRef = ref();
  228. const editFunRef = ref();
  229. const editEventRef = ref();
  230. const editTabRef = ref();
  231. const state = reactive<TableDataState>({
  232. isShowDialog: false,
  233. activeName: '1', // 分类数据
  234. activetab: 'attr', // 分类数据
  235. detail: {},
  236. developer_status: 0,
  237. tableData: {
  238. data: [],
  239. total: 0,
  240. loading: false,
  241. param: {
  242. pageNum: 1,
  243. productId: route.params && route.params.id,
  244. pageSize: 10,
  245. status: '',
  246. dateRange: [],
  247. },
  248. },
  249. });
  250. onMounted(() => {
  251. const ids = route.params && route.params.id;
  252. api.product.detail(ids).then((res: any) => {
  253. state.detail = res.data;
  254. state.developer_status = res.data.status
  255. });
  256. //第一次加载
  257. api.model.property(state.tableData.param).then((res: any) => {
  258. state.tableData.data = res.Data;
  259. state.tableData.total = res.Total;
  260. });
  261. });
  262. //编辑属性
  263. const onEditAttr = (row: TableDataRow) => {
  264. editAttrRef.value.openDialog(row, route.params.id);
  265. };
  266. //编辑功能
  267. const onEditFun = (row: TableDataRow) => {
  268. editFunRef.value.openDialog(row, route.params.id);
  269. }
  270. //编辑事件
  271. const onEditEvent = (row: TableDataRow) => {
  272. editEventRef.value.openDialog(row, route.params.id);
  273. }
  274. //编辑标签
  275. const onEditTag = (row: TableDataRow) => {
  276. editTabRef.value.openDialog(row, route.params.id);
  277. }
  278. //打开添加属性弹窗
  279. const onOpenEditAttr = () => {
  280. editAttrRef.value.openDialog({ product_id: route.params.id, id: 0, accessMode: 1 });
  281. };
  282. //打开添加功能弹窗
  283. const onOpenEditFun = () => {
  284. editFunRef.value.openDialog({ product_id: route.params.id, id: 0 });
  285. };
  286. //打开添加事件弹窗
  287. const onOpenEditEvent = () => {
  288. editEventRef.value.openDialog({ product_id: route.params.id, id: 0, level: 0 });
  289. };
  290. //打开添加事件弹窗
  291. const onOpenEditTab = () => {
  292. editTabRef.value.openDialog({ product_id: route.params.id, id: 0, accessMode: 1 });
  293. };
  294. // 打开修改产品弹窗
  295. const onOpenEditDic = (row: TableDataRow) => {
  296. editDicRef.value.openDialog(row);
  297. };
  298. // 删除产品
  299. const onRowDel = (key, type) => {
  300. let msg = `此操作将永久删除该数据,是否继续?`;
  301. if (key.length === 0) {
  302. ElMessage.error('请选择要删除的数据。');
  303. return;
  304. }
  305. ElMessageBox.confirm(msg, '提示', {
  306. confirmButtonText: '确认',
  307. cancelButtonText: '取消',
  308. type: 'warning',
  309. })
  310. .then(() => {
  311. if (type == 'attr') {
  312. api.model.propertydel(route.params.id, key).then(() => {
  313. ElMessage.success('删除成功');
  314. getproperty();
  315. });
  316. }
  317. if (type == 'fun') {
  318. api.model.functiondel(route.params.id, key).then(() => {
  319. ElMessage.success('删除成功');
  320. getfunction();
  321. });
  322. }
  323. if (type == 'event') {
  324. api.model.eventdel(route.params.id, key).then(() => {
  325. ElMessage.success('删除成功');
  326. getevent();
  327. });
  328. }
  329. if (type == 'tab') {
  330. api.model.tagdel(route.params.id, key).then(() => {
  331. ElMessage.success('删除成功');
  332. tagdel();
  333. });
  334. }
  335. })
  336. .catch(() => { });
  337. };
  338. //根据不同类型获取列表
  339. const getList = () => {
  340. switch (state.activetab) {
  341. case 'attr':
  342. getproperty();
  343. break;
  344. case 'fun':
  345. getfunction();
  346. break;
  347. case 'event':
  348. getevent();
  349. break;
  350. case 'tab':
  351. gettab();
  352. break;
  353. }
  354. };
  355. const getproperty = () => {
  356. api.model.property(state.tableData.param).then((res: any) => {
  357. state.tableData.data = res.Data;
  358. state.tableData.total = res.Total;
  359. });
  360. };
  361. const getfunction = () => {
  362. api.model.function(state.tableData.param).then((res: any) => {
  363. state.tableData.data = res.Data;
  364. state.tableData.total = res.Total;
  365. });
  366. };
  367. const getevent = () => {
  368. api.model.event(state.tableData.param).then((res: any) => {
  369. state.tableData.data = res.Data;
  370. state.tableData.total = res.Total;
  371. });
  372. };
  373. const gettab = () => {
  374. api.model.tag(state.tableData.param).then((res: any) => {
  375. state.tableData.data = res.Data;
  376. state.tableData.total = res.Total;
  377. });
  378. };
  379. const wuhandleClick = (tab: TabsPaneContext) => {
  380. state.activetab = tab.props.name;
  381. switch (tab.props.name) {
  382. case 'attr':
  383. getproperty();
  384. break;
  385. case 'fun':
  386. getfunction();
  387. break;
  388. case 'event':
  389. getevent();
  390. break;
  391. case 'tab':
  392. gettab();
  393. break;
  394. }
  395. };
  396. const handleClick = (tab: TabsPaneContext, event: Event) => {
  397. };
  398. const updateScript = (scriptInfo: string) => {
  399. state.detail.scriptInfo = scriptInfo
  400. };
  401. const CkOption = () => {
  402. if (state.developer_status == 1) {
  403. api.product.undeploy({ id: route.params.id }).then((res: any) => {
  404. ElMessage.success('操作成功');
  405. state.developer_status = 0;
  406. });
  407. } else {
  408. api.product.deploy({ id: route.params.id }).then((res: any) => {
  409. ElMessage.success('操作成功');
  410. state.developer_status = 1;
  411. });
  412. }
  413. }
  414. // 导出
  415. const onRowExport = () => {
  416. api.product.export({ key: state.detail.key }).then((res: any) => downloadFile(res, "TSL-" + state.detail.key + "-" + getCurrentTime() + ".json"))
  417. };
  418. const getCurrentTime = () => {
  419. const date = new Date();
  420. const year = date.getFullYear().toString();
  421. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  422. const day = date.getDate().toString().padStart(2, '0');
  423. const hours = date.getHours().toString().padStart(2, '0');
  424. const minutes = date.getMinutes().toString().padStart(2, '0');
  425. return year + month + day + hours + minutes;
  426. }
  427. const updateImg = (res: any) => {
  428. if (res.code === 0) {
  429. getList("attr");
  430. ElMessage.success('物模型导入成功');
  431. } else {
  432. ElMessage.error(res.message);
  433. }
  434. };
  435. return {
  436. updateImg,
  437. headers,
  438. uploadUrl,
  439. getCurrentTime,
  440. onRowExport,
  441. Edit,
  442. updateScript,
  443. editDicRef,
  444. editAttrRef,
  445. editFunRef,
  446. editEventRef,
  447. editTabRef,
  448. CkOption,
  449. onRowDel,
  450. onEditFun,
  451. onEditEvent,
  452. onEditTag,
  453. onEditAttr,
  454. getList,
  455. getproperty,
  456. getfunction,
  457. getevent,
  458. gettab,
  459. wuhandleClick,
  460. onOpenEditTab,
  461. onOpenEditEvent,
  462. onOpenEditAttr,
  463. onOpenEditFun,
  464. onOpenEditDic,
  465. handleClick,
  466. ...toRefs(state),
  467. };
  468. },
  469. });
  470. </script>
  471. <style scoped>
  472. .import {
  473. position: absolute;
  474. top: 8px;
  475. right: 12px;
  476. }
  477. .import .row_bet {
  478. display: flex;
  479. flex-direction: row;
  480. align-items: center;
  481. flex: 1;
  482. }
  483. .content {
  484. background: #fff;
  485. width: 100%;
  486. padding: 20px;
  487. }
  488. .cont_box {
  489. display: flex;
  490. }
  491. .cont_box .title {
  492. font-size: 24px;
  493. }
  494. .cont_box .pro-status {
  495. line-height: 40px;
  496. margin-left: 30px;
  497. }
  498. .cont_box .pro-status .on {
  499. background: #52c41a;
  500. }
  501. .cont_box .pro-status .off {
  502. background: #c41a1a;
  503. }
  504. .cont_box .pro-status span {
  505. position: relative;
  506. top: -1px;
  507. display: inline-block;
  508. width: 6px;
  509. height: 6px;
  510. vertical-align: middle;
  511. border-radius: 50%;
  512. margin-right: 5px;
  513. }
  514. .cont_box .pro-option {
  515. line-height: 40px;
  516. margin-left: 10px;
  517. color: #1890ff;
  518. cursor: pointer;
  519. }
  520. .pro-box {
  521. display: flex;
  522. padding: 10px;
  523. align-items: center;
  524. }
  525. .pro-box .protitle {
  526. font-size: 18px;
  527. font-weight: bold;
  528. line-height: 35px;
  529. }
  530. .pro-box .buttonedit {
  531. border: 0px;
  532. color: #1890ff;
  533. }
  534. .wu-title {
  535. display: flex;
  536. flex-direction: row;
  537. justify-content: space-between;
  538. padding: 20px;
  539. border-bottom: #e8e8e8 1px solid;
  540. }
  541. .wu-title .title {
  542. font-size: 18px;
  543. }
  544. </style>