index.vue 6.1 KB

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