WorkFaceReportTable.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="p-4">
  3. <div class="btm-group vent-flex-row-between">
  4. <div class="mb-10px">
  5. <JDictSelectTag v-model:value="deviceKind" placeholder="请输入设备类型" dictCode="analyReportType" />
  6. <a-button class="ml-5px mr-5px" type="primary" @click="handleAddDevices"> 新增 </a-button>
  7. <a-button type="primary" @click="handleAssoicate"> 自动关联 </a-button>
  8. </div>
  9. <!-- <a-button class="vent-margin-l-10" type="primary" @click="handleSave()"> 批量保存 </a-button> -->
  10. </div>
  11. <BasicTable ref="editTable" @register="registerTable">
  12. <template #action="{ record }">
  13. <TableAction
  14. :actions="[
  15. {
  16. label: '查看报表数据',
  17. onClick: () => handlePreview(record),
  18. },
  19. {
  20. label: '删除',
  21. popConfirm: {
  22. title: '确认删除?',
  23. confirm: () => handleDelete(record),
  24. },
  25. },
  26. ]"
  27. />
  28. </template>
  29. </BasicTable>
  30. <BasicModal title="手动关联报表数据" width="800px" @register="registerModal">
  31. <a-button type="primary" @click="handleSaveSelection"> 批量保存 </a-button>
  32. <BasicTable @register="registerTable2">
  33. <template #action="{ record }">
  34. <TableAction
  35. :actions="[
  36. {
  37. label: '保存',
  38. onClick: () => handleSave(record),
  39. },
  40. ]"
  41. />
  42. </template>
  43. </BasicTable>
  44. </BasicModal>
  45. </div>
  46. </template>
  47. <script lang="ts">
  48. import { defineComponent, ref, nextTick, watch } from 'vue';
  49. import { BasicModal, useModal } from '/@/components/Modal';
  50. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  51. import {
  52. deviceList,
  53. sceneReportAssociationList,
  54. sceneReportAssociationDelete,
  55. findPotentialAssociations,
  56. autoAssociate,
  57. manualAssociate,
  58. } from './point.api';
  59. import { reportColumns } from './point.data';
  60. import { message, Modal } from 'ant-design-vue';
  61. import { JDictSelectTag } from '/@/components/Form';
  62. import { JsonPreview } from '/@/components/CodeEditor';
  63. import { h } from 'vue';
  64. export default defineComponent({
  65. components: { BasicTable, TableAction, BasicModal, JDictSelectTag },
  66. props: {
  67. columns: {
  68. type: Array<any>,
  69. requried: true,
  70. },
  71. device: {
  72. type: Object,
  73. requried: true,
  74. default: () => ({}),
  75. },
  76. },
  77. emits: ['save', 'delete'],
  78. setup(props) {
  79. const deviceKind = ref('');
  80. const [registerModal, { openModal }] = useModal();
  81. const [registerTable, tableCtx] = useTable({
  82. columns: props.columns,
  83. title: '',
  84. api: ({ pageNo, pageSize }) => {
  85. return sceneReportAssociationList({
  86. pageNo,
  87. pageSize,
  88. sceneId: props.device.id,
  89. });
  90. },
  91. showIndexColumn: true,
  92. showTableSetting: false,
  93. tableSetting: { fullScreen: true },
  94. actionColumn: {
  95. width: 160,
  96. title: '操作',
  97. dataIndex: 'action',
  98. slots: { customRender: 'action' },
  99. },
  100. });
  101. const [registerTable2, tableCtx2] = useTable({
  102. columns: reportColumns,
  103. api() {
  104. return findPotentialAssociations({ sceneName: props.device.systemname, reportType: deviceKind.value });
  105. },
  106. pagination: false,
  107. rowSelection: { type: 'checkbox' },
  108. actionColumn: {
  109. width: 160,
  110. title: '操作',
  111. dataIndex: 'action',
  112. slots: { customRender: 'action' },
  113. },
  114. });
  115. function handleSave(record) {
  116. return manualAssociate([
  117. {
  118. ...record,
  119. sceneId: props.device.id,
  120. },
  121. ])
  122. .then((res) => {
  123. message.success(res);
  124. tableCtx.reload();
  125. tableCtx2.reload();
  126. })
  127. .catch((res) => {
  128. message.error(res.message);
  129. });
  130. }
  131. function handleSaveSelection() {
  132. return manualAssociate(
  133. tableCtx2.getSelectRows().map((e) => ({
  134. ...e,
  135. sceneId: props.device.id,
  136. }))
  137. )
  138. .then((res) => {
  139. message.success(res);
  140. tableCtx.reload();
  141. tableCtx2.reload();
  142. })
  143. .catch((res) => {
  144. message.error(res.message);
  145. });
  146. }
  147. function handleDelete(record) {
  148. return sceneReportAssociationDelete({
  149. id: record.id,
  150. })
  151. .then((res) => {
  152. message.success(res);
  153. tableCtx.reload();
  154. })
  155. .catch((res) => {
  156. message.error(res.message);
  157. });
  158. }
  159. function handleAssoicate() {
  160. if (!deviceKind.value) return message.info('请选择设备类型');
  161. return autoAssociate({
  162. reportType: deviceKind.value,
  163. })
  164. .then((res) => {
  165. message.success(res);
  166. tableCtx.reload();
  167. })
  168. .catch((res) => {
  169. message.error(res.message);
  170. });
  171. }
  172. function handlePreview(record) {
  173. Modal.info({
  174. title: record.reportPointName,
  175. width: 700,
  176. content: h(JsonPreview, {
  177. data: record.reportJsonData,
  178. style: { backgroundColor: '#333', marginRight: '38px' },
  179. }),
  180. });
  181. }
  182. function handleAddDevices() {
  183. if (!deviceKind.value) return message.info('请选择设备类型');
  184. openModal();
  185. nextTick(() => tableCtx2.reload());
  186. }
  187. watch(
  188. () => props.columns,
  189. (columns = []) => {
  190. // linkColumns.value = columns
  191. // reload()
  192. tableCtx.setColumns(columns);
  193. }
  194. );
  195. return {
  196. registerTable,
  197. registerTable2,
  198. deviceKind,
  199. deviceList,
  200. registerModal,
  201. handleAddDevices,
  202. handleSave,
  203. handleAssoicate,
  204. handleDelete,
  205. handleSaveSelection,
  206. handlePreview,
  207. };
  208. },
  209. });
  210. </script>
  211. <style scoped lang="less">
  212. @ventSpace: zxm;
  213. :deep(.@{ventSpace}-table-body) {
  214. height: auto !important;
  215. }
  216. .btm-group {
  217. padding-bottom: 2px;
  218. }
  219. .device-button-group {
  220. // margin: 0 20px;
  221. display: flex;
  222. flex-wrap: wrap;
  223. pointer-events: auto;
  224. position: relative;
  225. margin-top: 10px;
  226. margin-bottom: 5px;
  227. &::after {
  228. position: absolute;
  229. content: '';
  230. width: calc(100% + 10px);
  231. height: 2px;
  232. top: 30px;
  233. left: -10px;
  234. border-bottom: 1px solid #0efcff;
  235. }
  236. .device-button {
  237. padding: 4px 10px;
  238. position: relative;
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. font-size: 14px;
  243. color: #fff;
  244. cursor: pointer;
  245. margin: 0 1px;
  246. &::before {
  247. content: '';
  248. position: absolute;
  249. top: 0;
  250. right: 0;
  251. bottom: 0;
  252. left: 0;
  253. border: 1px solid #6176af;
  254. // transform: skewX(-38deg);
  255. background-color: rgba(0, 77, 103, 85%);
  256. z-index: -1;
  257. }
  258. }
  259. .device-active {
  260. // color: #0efcff;
  261. &::before {
  262. border-color: #0efcff;
  263. box-shadow: 1px 1px 3px 1px #0efcff inset;
  264. }
  265. }
  266. }
  267. </style>