SharedTable.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="camera-share">
  3. <div class="flex items-center query-head">
  4. <el-space alignment="center" :size="50">
  5. <div style="display: flex">
  6. <div>公司名称:</div>
  7. <el-input
  8. v-model="queryName"
  9. clearable
  10. placeholder="请输入公司名称"
  11. class="query-content"
  12. />
  13. </div>
  14. <div>
  15. <span>公司账号:</span>
  16. <el-input
  17. v-model="queryAccount"
  18. clearable
  19. placeholder="请输入公司账号"
  20. class="query-content"
  21. />
  22. </div>
  23. </el-space>
  24. <div class="flex-1 flex justify-end">
  25. <el-button type="primary" @click="queryCameraItems"> 查询 </el-button>
  26. <el-button @click="resetSearch"> 重置 </el-button>
  27. </div>
  28. </div>
  29. <div class="camera-list">
  30. <!-- :data-source="props.addCameraType === 'complete' ? cameraCompleted : cameraIncompleted" -->
  31. <BasicTable
  32. :columns="getColumns(flattendWorkspaces)"
  33. :data-source="cameraShareList"
  34. :row-key="(row) => row.cameraIp"
  35. :action-column="actionColumn"
  36. :tableSetting="{
  37. size: false,
  38. redo: false,
  39. fullscreen: false,
  40. striped: false,
  41. setting: false,
  42. }"
  43. :striped="true"
  44. ref="tableRef"
  45. />
  46. </div>
  47. <CameraEditshared
  48. class="add-popover"
  49. v-model="shareEditedPopover"
  50. :edit-data="handleEditData"
  51. />
  52. </div>
  53. </template>
  54. <script setup lang="ts">
  55. import { h, reactive, ref, onMounted, watch, onBeforeMount } from 'vue';
  56. import { getColumns } from '../sharedColumns';
  57. import editIcon from '@/assets/images/table/table-edit.png';
  58. import deleteIcon from '@/assets/images/table/table-delete.png';
  59. import { BasicColumn, TableActionIconsWords, BasicTable } from '@/components/Table';
  60. import CameraEditshared from '../components/CameraEditshared.vue';
  61. import useCameraShare from '../stores/useCameraShare';
  62. import useSceneInfos from '@/hooks/useSceneInfos';
  63. import { CameraShareType } from '@/api/camera/camera-share';
  64. const useShare = useCameraShare();
  65. const {
  66. cameraShareList,
  67. queryName,
  68. queryAccount,
  69. isAddState,
  70. queryToTenantId,
  71. conditionSearch,
  72. handleDel,
  73. handleEdit,
  74. } = useShare;
  75. const sceneInfos = useSceneInfos();
  76. const { flattendWorkspaces, getScenesTree } = sceneInfos;
  77. const props = defineProps<{ addCameraType: string }>();
  78. onMounted(() => {
  79. isAddState.value = props.addCameraType === 'incomplete' ? false : true;
  80. console.log('isAddState', isAddState.value);
  81. queryToTenantId.value = -10;
  82. conditionSearch();
  83. console.log(cameraShareList.value);
  84. });
  85. const shareEditedPopover = ref<boolean>(false);
  86. const handleEditData = ref<CameraShareType>({} as CameraShareType);
  87. const handleEditDetail = (row) => {
  88. shareEditedPopover.value = true;
  89. row.cameraWorkspaceName = flattendWorkspaces.value?.find(
  90. (item) => item.id === Number(row.cameraWorkspace),
  91. )?.code;
  92. handleEditData.value = row;
  93. };
  94. // const updateData = (_data) => {
  95. // // if (props.addCameraType === 'complete') {
  96. // // const indexToEdit = cameraIncompleted.value.findIndex(
  97. // // (item) => item.cameraIp === data.cameraIp,
  98. // // );
  99. // // cameraIncompleted.value[indexToEdit] = data;
  100. // // } else {
  101. // // const indexToEdit = cameraCompleted.value.findIndex(
  102. // // (item) => item.cameraIp === data.cameraIp,
  103. // // );
  104. // // cameraCompleted.value[indexToEdit] = data;
  105. // // }
  106. // };
  107. //添加按钮
  108. const handleChangeAdd = (row) => {
  109. const changeAddData = {
  110. id: row.id,
  111. isAdd: row.isAdd ? false : true,
  112. };
  113. handleEdit(changeAddData);
  114. };
  115. const handleDelete = (row) => {
  116. console.log('row', row);
  117. handleDel(row.id);
  118. };
  119. //操作列
  120. const actionColumn: BasicColumn = reactive({
  121. width: 200,
  122. title: '操作',
  123. prop: 'action',
  124. key: 'action',
  125. fixed: 'right',
  126. render(record) {
  127. return h(TableActionIconsWords as any, {
  128. space: 20,
  129. color: '#629bf9',
  130. style: 'img',
  131. size: 16,
  132. actionIcons: [
  133. {
  134. label: '添加',
  135. type: 'words' + props.addCameraType,
  136. onClick: handleChangeAdd.bind(null, record.row),
  137. },
  138. {
  139. label: '编辑',
  140. type: 'img',
  141. icon: editIcon,
  142. onClick: handleEditDetail.bind(null, record.row),
  143. },
  144. {
  145. label: '删除',
  146. type: 'img',
  147. icon: deleteIcon,
  148. onClick: handleDelete.bind(null, record.row),
  149. },
  150. ],
  151. });
  152. },
  153. });
  154. //查询
  155. const queryCameraItems = () => {
  156. isAddState.value = props.addCameraType === 'incomplete' ? false : true;
  157. conditionSearch();
  158. };
  159. //重置
  160. const resetSearch = () => {
  161. queryName.value = '';
  162. queryAccount.value = '';
  163. };
  164. watch(
  165. () => props.addCameraType,
  166. (_val) => {
  167. resetSearch();
  168. isAddState.value = props.addCameraType === 'incomplete' ? false : true;
  169. console.log('isAddState', isAddState.value);
  170. conditionSearch();
  171. },
  172. );
  173. onBeforeMount(() => {
  174. getScenesTree({ level: 3, valueKey: 'code', labelKey: 'name', disabled: true });
  175. });
  176. </script>
  177. <style scoped>
  178. .type-select {
  179. width: 100px;
  180. }
  181. .query-content {
  182. width: 160px;
  183. margin-top: -6px;
  184. }
  185. .protocal-select {
  186. width: 160px;
  187. }
  188. .query-head {
  189. padding: 24px 57px 18px 21px;
  190. }
  191. .camera-share {
  192. position: relative;
  193. height: calc(100vh - 64px - 12px);
  194. background-color: #ffffff;
  195. }
  196. .camera-list {
  197. padding: 0 21px;
  198. }
  199. .add-popover {
  200. position: absolute;
  201. width: calc(100%);
  202. height: 622px;
  203. top: -57px;
  204. left: -20px;
  205. margin: auto;
  206. z-index: 99;
  207. }
  208. </style>