index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <PageWrapper contentBackground>
  3. <div class="desc-wrap-BasicTable">
  4. <BasicTable @register="registerTable">
  5. </BasicTable>
  6. </div>
  7. </PageWrapper>
  8. </template>
  9. <script lang="ts">
  10. import { defineComponent, h, onMounted } from 'vue';
  11. import {
  12. BasicTable,
  13. useTable,
  14. TableAction,
  15. BasicColumn,
  16. TableImg,
  17. FormProps,
  18. } from '/@/components/Table';
  19. import { PageWrapper } from '/@/components/Page';
  20. import { Descriptions } from 'ant-design-vue';
  21. import { useI18n } from '/@/hooks/web/useI18n';
  22. import { useMessage } from '/@/hooks/web/useMessage';
  23. import { cameraList } from '/@/api/customer';
  24. import { cameraDelete } from '/@/api/device';
  25. import { useRouter } from 'vue-router';
  26. import { UnbindCameraApi } from '/@/api/account';
  27. import { usePermissionStore } from '/@/store/modules/permission';
  28. export default defineComponent({
  29. components: {
  30. BasicTable,
  31. TableAction,
  32. PageWrapper,
  33. TableImg,
  34. [Descriptions.name]: Descriptions,
  35. [Descriptions.Item.name]: Descriptions.Item,
  36. },
  37. setup() {
  38. const { t } = useI18n();
  39. const { createMessage, createConfirm } = useMessage();
  40. const permissionStore = usePermissionStore();
  41. const { getCheckPerm } = permissionStore;
  42. const router = useRouter();
  43. const companyId: Number = router.currentRoute.value.params.id - 0;
  44. onMounted(() => {
  45. // console.log(router.currentRoute.value.params.id);
  46. });
  47. const columns: BasicColumn[] = [
  48. {
  49. title: t('routes.device.snCode'),
  50. dataIndex: 'snCode',
  51. width: 180,
  52. },
  53. {
  54. title: t('routes.device.wifiName'),
  55. dataIndex: 'wifiName',
  56. width: 150,
  57. },
  58. {
  59. title: t('routes.device.deviceType'),
  60. dataIndex: 'type',
  61. ellipsis: false,
  62. width: 80,
  63. customRender: ({ record }) => {
  64. let typeObj ={
  65. '0':t('routes.device.type.0'),
  66. '1':t('routes.device.type.1'),
  67. '2':t('routes.device.type.2'),
  68. '9':t('routes.device.type.9'),
  69. '10':t('routes.device.type.10'),
  70. }
  71. return typeObj[record.type]
  72. }
  73. },
  74. {
  75. title: t('routes.device.activatedTime'),
  76. dataIndex: 'activatedTime',
  77. width: 180,
  78. },
  79. {
  80. title: t('routes.device.userName'),
  81. dataIndex: 'userName',
  82. width: 180,
  83. customRender({ record }) {
  84. return record.userName?record.userName:'-'
  85. },
  86. },
  87. ];
  88. const searchForm: Partial<FormProps> = {
  89. labelWidth: 80,
  90. autoAdvancedLine:1,
  91. actionColOptions: {
  92. span: 24,
  93. },
  94. schemas: [
  95. {
  96. field: 'snCode',
  97. component: 'Input',
  98. label: t('routes.device.snCode'),
  99. colProps: {
  100. xl: 6,
  101. xxl: 6,
  102. },
  103. },{
  104. field: 'type',
  105. component: 'Select',
  106. label: t('routes.device.deviceType'),
  107. colProps: {
  108. xl: 6,
  109. xxl: 6,
  110. },
  111. componentProps: {
  112. options: [
  113. {
  114. // label: t('routes.device.type.0'),
  115. // value: 0,
  116. // key: '0',
  117. // },{
  118. label: t('routes.device.type.1'),
  119. value: 1,
  120. key: '1',
  121. },{
  122. label: t('routes.device.type.2'),
  123. value: 9,
  124. key: '9',
  125. },{
  126. label: t('routes.device.type.3'),
  127. value: 10,
  128. key: '10',
  129. },
  130. ],
  131. },
  132. },
  133. {
  134. field: 'userName',
  135. component: 'Input',
  136. label: t('routes.device.userName'),
  137. colProps: {
  138. xl: 6,
  139. xxl: 6,
  140. },
  141. },
  142. ],
  143. };
  144. const [registerTable, { reload }] = useTable({
  145. api: cameraList,
  146. columns: columns,
  147. searchInfo: { companyId },
  148. useSearchForm: true,
  149. formConfig: searchForm,
  150. showTableSetting: true,
  151. showIndexColumn:false,
  152. rowKey: 'id',
  153. beforeFetch:(T)=>{
  154. if(T.ctivated){
  155. T.activatedStartTime = T.ctivated[0]
  156. T.activatedEndTime = T.ctivated[1]
  157. }
  158. return T
  159. },
  160. fetchSetting: {
  161. pageField: 'pageNum',
  162. sizeField: 'pageSize',
  163. listField: 'list',
  164. totalField: 'total',
  165. },
  166. canResize: false,
  167. });
  168. async function handleUnbind(record: Recordable) {
  169. createConfirm({
  170. iconType: 'warning',
  171. title: () => h('span', t('common.optSuccess')),
  172. content: '解绑后用户将看不到该相机拍摄的场景。<br/>确定解绑吗?',
  173. onOk: async () => {
  174. await UnbindCameraApi({cameraId:record.id})
  175. createMessage.success(t('common.optSuccess'));
  176. reload()
  177. },
  178. });
  179. }
  180. async function handleDelete(record: Recordable){
  181. createConfirm({
  182. iconType: 'warning',
  183. title: () => h('span', t('common.optSuccess')),
  184. content: '删除设备后需要重新入库<br/>确定删除吗?',
  185. onOk: async () => {
  186. await cameraDelete({id:record.id})
  187. createMessage.success(t('common.optSuccess'));
  188. reload()
  189. },
  190. });
  191. }
  192. return {
  193. registerTable,
  194. handleUnbind,
  195. reload,
  196. handleDelete,
  197. getCheckPerm,
  198. };
  199. },
  200. });
  201. </script>
  202. <style lang="less" scoped>
  203. .desc-wrap-BasicTable {
  204. background-color: #f0f2f5;
  205. .vben-basic-table-form-container {
  206. padding: 0;
  207. }
  208. }
  209. </style>