index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <div class="layout-pd">
  3. <el-row>
  4. <!--操作-->
  5. <el-col :xs="24">
  6. <el-card class="mt8" shadow="hover">
  7. <el-form :model="sdkData.Filter" @submit.stop.prevent>
  8. <el-form-item prop="name" style="width: 100%">
  9. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  10. <el-form-item label="油站名称">
  11. <el-input v-model="sdkData.Filter.OilStation" placeholder="单行输入" clearable></el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  15. <el-form-item label="项目名称">
  16. <el-input v-model="sdkData.Filter.Project" placeholder="单行输入" clearable></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  20. <el-form-item label="SN号">
  21. <el-input v-model="sdkData.Filter.SN" placeholder="单行输入" clearable></el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  25. <el-form-item label="授权码">
  26. <el-input v-model="sdkData.Filter.Key" placeholder="单行输入" clearable></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  30. <el-form-item label="状态">
  31. <el-select placeholder="请选择上传状态">
  32. <el-option label="所有" :value="''"></el-option>
  33. <el-option label="正常" :value="''"></el-option>
  34. <el-option label="未授权" :value="''"></el-option>
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  39. <el-form-item label="失效时间">
  40. <el-date-picker v-model="sdkData.time" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
  41. range-separator="To" start-placeholder="开始日期" end-placeholder="结束日期" />
  42. </el-form-item>
  43. </el-col>
  44. </el-form-item>
  45. </el-form>
  46. <hr>
  47. <!-- 按钮 -->
  48. <el-row justify="space-between" class="submit-button">
  49. <el-row>
  50. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  51. <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
  52. </el-row>
  53. <el-row>
  54. <el-button type="primary" icon="ele-CirclePlus" @click="onAdd"> 添加 </el-button>
  55. <el-button type="primary" icon="ele-Tickets" @click="onAuditRecord()"> 审核 </el-button>
  56. <el-button type="primary" icon="ele-UploadFilled" @click="uploadFiles"> 批量导入 </el-button>
  57. <el-button type="primary" icon="ele-Document"
  58. @click="exportTable(sdkData.tableModel, sdkData.dynamicColumns)"> 导出表格 </el-button>
  59. </el-row>
  60. </el-row>
  61. </el-card>
  62. </el-col>
  63. <!--表格-->
  64. <el-col :xs="24">
  65. <el-card class="my-fill mt8" shadow="hover">
  66. <el-table
  67. ref="multipleTableRef"
  68. v-loading="sdkData.loading"
  69. stripe
  70. :data="sdkData.tableModel"
  71. row-key="id"
  72. style="width: 100%"
  73. @row-click="onOilSdkRowClick"
  74. >
  75. <el-table-column type="selection" width="50"></el-table-column>
  76. <el-table-column
  77. v-for="column in sdkData.dynamicColumns"
  78. :key="column.prop"
  79. :prop="column.prop"
  80. :label="column.label"
  81. >
  82. <template #default="{ row }">
  83. <template v-if="column.prop === 'state'">
  84. <StatusBox :status="row.state" />
  85. </template>
  86. <template v-else>
  87. {{ row[column.prop] }}
  88. </template>
  89. </template>
  90. </el-table-column>
  91. <!-- 操作列保持不变 -->
  92. <el-table-column label="操作" fixed="right" width="100">
  93. <template #default="{ row }">
  94. <el-link icon="ele-Edit" @click="editTableData(row)">
  95. 编辑
  96. </el-link>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <div class="my-flex my-flex-end" style="margin-top: 20px">
  101. <el-pagination v-model:currentPage="sdkData.pageInput.CurrentPage"
  102. v-model:page-size="sdkData.pageInput.PageSize" :total="sdkData.total"
  103. :page-sizes="[10000, 20000, 50000, 100000]" small background @size-change="onSizeChange"
  104. @current-change="onCurrentChange" layout="total, sizes, prev, pager, next, jumper" />
  105. </div>
  106. </el-card>
  107. </el-col>
  108. </el-row>
  109. <EditDialog ref="editDialogRef" />
  110. <AuditDialog ref="auditDialogRef" />
  111. </div>
  112. </template>
  113. <script setup lang="ts" name="authorize/fuelingsdk">
  114. import { defineAsyncComponent, onMounted, reactive, ref, watch, onBeforeMount, getCurrentInstance } from "vue";
  115. import { OilSdkAuthorDto, oilSdkFilterModel, oilSdkTableModel, oilSdkAuthorPageOutput, FueilingSdkAuthInput } from "/@/api/admin/deviceAuthorization/oilSdkAuthorDto";
  116. import { OilSdkAuthorAPI } from "/@/api/admin/deviceAuthorization/oilSdkAuthor";
  117. import type { pageInput } from "/@/api/admin/shareDto/shareDto";
  118. import eventBus from "/@/utils/mitt";
  119. import * as ExcelJS from 'exceljs';
  120. import * as FileSaver from 'file-saver';
  121. import { ElTable } from 'element-plus'
  122. import StatusBox from "/@/components/StatusBox.vue";
  123. /**引入组件*/
  124. const EditDialog = defineAsyncComponent(() => import('/src/views/admin/authorize/fuelingsdk/components/form-edit.vue'))
  125. const AuditDialog = defineAsyncComponent(() => import('/src/views/admin/authorize/fuelingsdk/components/form-audit.vue'))
  126. const editDialogRef = ref()
  127. const auditDialogRef = ref()
  128. const multipleTableRef = ref<InstanceType<typeof ElTable>>()
  129. const { proxy } = getCurrentInstance() as any
  130. /**sdk授权页面对象 */
  131. const sdkData = reactive({
  132. time: '',
  133. /**加载显示 */
  134. loading: false,
  135. /**条件查询模块 */
  136. Filter: {
  137. /**油站名称 */
  138. OilStation: "",
  139. /**项目名称 */
  140. Project: "",
  141. /**设备SN */
  142. SN: "",
  143. /**授权码*/
  144. Key: "",
  145. /**开始的时间 */
  146. BeginTime: null,
  147. /**开始的时间 */
  148. EndTime: null,
  149. } as oilSdkFilterModel,
  150. /**表格信息 */
  151. tableModel: [] as oilSdkTableModel,
  152. /**动态表头 */
  153. dynamicColumns: [
  154. { prop: 'guid', label: '编号' },
  155. { prop: 'oilStation', label: '油站名称' },
  156. { prop: 'projectName', label: '项目名称' },
  157. { prop: 'sn', label: '设备SN号' },
  158. { prop: 'key', label: '授权码' },
  159. { prop: 'expiedTime', label: '失效时间' },
  160. { prop: 'state', label: '状态' },
  161. { prop: 'remark', label: '备注' },
  162. ],
  163. /**分页标识 */
  164. pageInput: {
  165. CurrentPage: 1,
  166. PageSize: 10000,
  167. } as pageInput,
  168. /**分页总数 */
  169. total: 0,
  170. } as OilSdkAuthorDto)
  171. /**初始化 */
  172. const init = async () => {
  173. sdkData.loading = true
  174. const query = flattenObject({ Filter: sdkData.Filter })
  175. const res: any = await new OilSdkAuthorAPI().getPageData({ ...sdkData.pageInput, ...query }).catch(() => {
  176. sdkData.loading = false
  177. })
  178. sdkData.tableModel = res?.data?.list ?? []
  179. sdkData.total = res?.data?.total ?? 0
  180. sdkData.loading = false
  181. }
  182. onMounted(() => {
  183. init()
  184. eventBus.off('refreshView')
  185. eventBus.on('refreshView', async () => {
  186. init()
  187. })
  188. })
  189. onBeforeMount(() => {
  190. eventBus.off('refreshView')
  191. })
  192. /**
  193. * 监听时间变换
  194. */
  195. watch(() => sdkData.time, (newVal) => {
  196. if (newVal.length === 0) {
  197. return
  198. }
  199. sdkData.Filter.BeginTime = newVal?.[0].toString()
  200. sdkData.Filter.EndTime = newVal?.[1].toString()
  201. })
  202. /**条件查询 */
  203. const onQuery = () => {
  204. init()
  205. }
  206. /**重置查询条件 */
  207. const resetQuery = () => {
  208. sdkData.Filter.OilStation = ''
  209. sdkData.Filter.Project = ''
  210. sdkData.Filter.SN = ''
  211. sdkData.Filter.Key = ''
  212. sdkData.Filter.BeginTime = ''
  213. sdkData.Filter.EndTime = ''
  214. sdkData.time = ''
  215. sdkData.pageInput.CurrentPage = 1
  216. }
  217. /**重置 */
  218. const onReset = () => {
  219. resetQuery()
  220. init()
  221. }
  222. /**添加*/
  223. const onAdd = () => {
  224. editDialogRef.value.openDialog()
  225. }
  226. /**页条数变化*/
  227. const onSizeChange = () => {
  228. init()
  229. }
  230. /**页数变化*/
  231. const onCurrentChange = () => {
  232. init()
  233. }
  234. /**批量导入*/
  235. const uploadFiles = () => {
  236. }
  237. /**导出表格*/
  238. const exportTable = async (data: any[], columns: { prop: string, label: string }[]) => {
  239. // 创建一个新的工作簿
  240. const workbook = new ExcelJS.Workbook();
  241. const worksheet = workbook.addWorksheet('Sheet1');
  242. // 添加表头(不包括名为 "guid" 的表头列)
  243. const headers = columns
  244. .filter(column => column.prop !== 'guid') // 过滤掉名为 "guid" 的表头列
  245. .map(column => column.label);
  246. const headerRow = worksheet.addRow(headers);
  247. // 添加数据行(不包括 "guid" 的数据列)
  248. data.forEach((item) => {
  249. const row = columns
  250. .filter(column => column.prop !== 'guid') // 过滤掉名为 "guid" 的数据列
  251. .map(column => item[column.prop]);
  252. worksheet.addRow(row);
  253. });
  254. // 设置数据行样式
  255. worksheet.eachRow({ includeEmpty: true }, row => {
  256. row.eachCell(cell => {
  257. // 设置单元格样式
  258. cell.font = { bold: false }; // 设置字体为普通样式
  259. cell.border = { top: { style: 'thin' }, bottom: { style: 'thin' } }; // 设置上下边框为细线
  260. cell.alignment = { vertical: 'middle', horizontal: 'center' }; // 将内容垂直居中、水平居中
  261. // 设置单元格高度
  262. row.height = 25; // 设置每一行的高度为 25
  263. });
  264. });
  265. // 设置表头样式
  266. headerRow.font = { bold: true }; // 设置字体为粗体
  267. // 设置整个表格的边框样式
  268. worksheet.eachRow({ includeEmpty: true }, row => {
  269. row.eachCell(cell => {
  270. if (cell.row === 1) {
  271. // 设置表头单元格的边框为细线
  272. cell.border = { left: { style: 'thin' }, right: { style: 'thin' }, top: { style: 'thin' }, bottom: { style: 'thin' } };
  273. // 设置表头单元格背景颜色
  274. cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: '409eff' } }
  275. } else {
  276. // 设置数据行单元格的边框为细线
  277. cell.border = { left: { style: 'thin' }, right: { style: 'thin' }, bottom: { style: 'thin' } };
  278. }
  279. });
  280. });
  281. // 调整单元格大小
  282. worksheet.columns.forEach(column => {
  283. column.width = 25; // 设置每列的宽度为 25
  284. });
  285. // 生成 Excel 文件
  286. const buffer = await workbook.xlsx.writeBuffer();
  287. // 将文件保存到本地
  288. const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
  289. FileSaver.saveAs(blob, '油气SDK授权数据.xlsx');
  290. }
  291. /**将Filter对象成.的连接方式*/
  292. const flattenObject = (obj, parentKey = '') => {
  293. const result = {};
  294. for (const key in obj) {
  295. if (obj.hasOwnProperty(key)) {
  296. const newKey = parentKey ? `${parentKey}.${key}` : key;
  297. if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
  298. const flattened = flattenObject(obj[key], newKey);
  299. Object.assign(result, flattened);
  300. } else {
  301. result[newKey] = obj[key];
  302. }
  303. }
  304. }
  305. return result;
  306. }
  307. /**编辑弹窗 */
  308. const editTableData = (row) => {
  309. editDialogRef.value.openDialog(row)
  310. }
  311. /**审核弹窗 */
  312. const onAuditRecord = () => {
  313. const selectionRows = multipleTableRef.value!.getSelectionRows() as FueilingSdkAuthInput
  314. //console.log(selectionRows)
  315. if (!((selectionRows.length as number) > 0)) {
  316. proxy.$modal.msgWarning('请选择要审核的数据')
  317. return
  318. } else {
  319. auditDialogRef.value.openDialog(selectionRows)
  320. }
  321. }
  322. const onOilSdkRowClick = (row: FueilingSdkAuthInput) => {
  323. // TODO: improvement typing when refactor table
  324. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  325. // @ts-expect-error
  326. multipleTableRef.value!.toggleRowSelection(row, undefined)
  327. }
  328. </script>
  329. <style scoped lang="scss">
  330. .el-input,
  331. .el-select {
  332. width: 240px;
  333. }
  334. /* 输入框标签固定四个字符宽度 */
  335. ::v-deep .el-form-item__label {
  336. // 字体大小14,4个字符,12px右间距
  337. width: 14*4px+12px;
  338. justify-content: start;
  339. }
  340. /* 数据表头 设置灰色样式 */
  341. ::v-deep .el-table th.el-table__cell {
  342. background-color: #F6F6F6;
  343. }
  344. </style>