index.vue 13 KB

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