index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="layout-pd">
  3. <el-row>
  4. <!--操作-->
  5. <el-col :xs="24">
  6. <el-card class="mt8" shadow="never" :body-style="{ paddingBottom: '0' }">
  7. <div style="width: 100%;">
  8. <h1 style="margin-bottom: 10px;font-size: 30px;display: flex;justify-content: center;align-items: center;">
  9. 油机非当天动态密钥生成</h1>
  10. </div>
  11. <div v-if="state.msgDisplay" style="width: 100%;">
  12. <h1 style="margin-bottom: 10px;color: #81B337;font-size: 20px;">密码申请成功</h1>
  13. </div>
  14. <div style="width: 100%;margin-top:20px">
  15. <el-form :inline="true" @submit.stop.prevent style="width: 60%;">
  16. <el-form-item label="申请备注" style="width: 40%;">
  17. <el-input v-model="state.filter.info" style="width: 100%;" placeholder="请输入申请备注"
  18. @keyup.enter="onQuery" />
  19. </el-form-item>
  20. <el-form-item label="密钥使用日期" style="width: 45%;">
  21. <el-date-picker
  22. v-model="state.filter.useDate"
  23. type="date"
  24. style="width: 100%;"
  25. placeholder="请选择日期"
  26. value-format="yyyy/MM/DD"
  27. />
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. <div v-if="state.pwdDisplay" style="width: 100%;">
  32. <el-form :inline="true" @submit.stop.prevent style="width: 60%;">
  33. <el-form-item label="FTP密码" style="width: 82%;">
  34. <el-input disabled v-model="state.pwd" style="width: 100%;" placeholder="FTP密码"
  35. @keyup.enter="onQuery" />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button id="copyBtn" :data-clipboard-text="state.pwd" type="primary" @click="onCopy()">复制</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <div v-if="state.timeDisplay" style="width: 100%;">
  43. <el-form :inline="true" @submit.stop.prevent style="width: 60%;">
  44. <el-form-item label="过期时间" style="width: 100%;">
  45. {{ state.filter.expirationTime }}
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <hr>
  50. <!-- 按钮 -->
  51. <el-row justify="space-between" class="submit-button">
  52. <el-row>
  53. </el-row>
  54. <el-row>
  55. <div v-if="state.btnDisplay" style="display: flex;justify-content: center;align-items: center;">
  56. <el-button style="margin-top: 10px;margin-bottom: 10px;width: 264px;height: 42px;" type="primary"
  57. @click="onQuery">申请油机FTP密码</el-button>
  58. </div>
  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 ref="multipleTableRef" v-loading="state.loading" stripe :data="state.tableModel" row-key="id"
  67. style="width: 100%">
  68. <el-table-column type="index" label="记录" width="60" />
  69. <el-table-column v-for="column in state.dynamicColumns" :key="column.prop" :prop="column.prop"
  70. :label="column.label" />
  71. </el-table>
  72. <div class="my-flex my-flex-end" style="margin-top: 20px">
  73. <el-pagination v-model:currentPage="pageState.pageInput.currentPage"
  74. v-model:page-size="pageState.pageInput.pageSize" :total="state.total" :page-sizes="[10, 15, 20, 50, 100]" small
  75. background @size-change="onSizeChange" @current-change="onCurrentChange"
  76. layout="total, sizes, prev, pager, next, jumper" />
  77. </div>
  78. </el-card>
  79. </el-col>
  80. </el-row>
  81. </div>
  82. </template>
  83. <script setup lang="ts" name="authorize/fuelingsdk">
  84. import { onMounted, reactive, ref, watch, onBeforeMount } from "vue";
  85. import eventBus from "/@/utils/mitt";
  86. import { ElMessage, ElTable } from 'element-plus'
  87. import { FuelingFtpAPI } from '/@/api/admin/deviceAuthorization/fuelingFTPApi'
  88. import { FuelFtpPswRecordDto } from '/@/api/admin/deviceAuthorization/fuelingFTPDto'
  89. import Clipboard from 'clipboard'
  90. import type { pageInput } from "/@/api/admin/shareDto/shareDto";
  91. import { AuthApi } from '/@/api/admin/Auth'
  92. import { useDynamicPageSize } from "/@/composables/useDynamicPageSize";
  93. // 使用组合式函数获取分页状态
  94. const pageState = useDynamicPageSize(10, 15);
  95. const multipleTableRef = ref<InstanceType<typeof ElTable>>()
  96. /**FTP申请页面对象 */
  97. const state = reactive({
  98. time: '',
  99. /**加载显示 */
  100. loading: false,
  101. /**条件查询模块 */
  102. filter: {
  103. /**申请备注 */
  104. info: "",
  105. /**过期时间 */
  106. expirationTime: '',
  107. /**使用日期*/
  108. useDate: '',
  109. /**申请日期*/
  110. applyDate: '',
  111. /**申请人*/
  112. name: ''
  113. },
  114. /**分页标识 */
  115. pageInput: {
  116. CurrentPage: 1,
  117. PageSize: 10,
  118. } as pageInput,
  119. /**分页总数 */
  120. total: 0,
  121. /**表格信息 */
  122. tableModel: [] as FuelFtpPswRecordDto,
  123. /**动态表头 */
  124. dynamicColumns: [
  125. { prop: 'applyDate', label: '申请日期' },
  126. { prop: 'name', label: '申请人' },
  127. { prop: 'info', label: '备注' },
  128. { prop: 'useDate', label: '密钥使用日期' },
  129. { prop: 'expirationTime', label: '密钥过期时间' }
  130. ],
  131. /**FTP密码 */
  132. pwd: "",
  133. pwdDisplay: false,
  134. timeDisplay: false,
  135. btnDisplay: true,
  136. msgDisplay: false
  137. })
  138. /**初始化 */
  139. const init = async () => {
  140. state.filter.info = ''
  141. state.filter.name = ''
  142. state.filter.applyDate = ''
  143. state.filter.expirationTime = ''
  144. state.filter.useDate = ''
  145. state.pwd = ''
  146. state.btnDisplay = true
  147. state.msgDisplay = false
  148. state.pwdDisplay = false
  149. state.timeDisplay = false
  150. const res: any = await new FuelingFtpAPI().getFtpDate({ ...state.pageInput, filter: state.filter }).catch(() => {
  151. state.loading = false
  152. })
  153. //console.log(res.data.list)
  154. state.total = res.data.total
  155. state.tableModel = res.data.list
  156. }
  157. onMounted(() => {
  158. // 初始化分页大小
  159. state.pageInput.PageSize = pageState.pageInput.pageSize;
  160. init()
  161. eventBus.off('refreshView')
  162. eventBus.on('refreshView', async () => {
  163. init()
  164. })
  165. })
  166. onBeforeMount(() => {
  167. eventBus.off('refreshView')
  168. })
  169. /**
  170. * 监听时间变换
  171. */
  172. watch(() => state.time, (newVal) => {
  173. if (newVal.length === 0) {
  174. return
  175. }
  176. state.filter.expirationTime = newVal?.[0].toString()
  177. })
  178. /**复制FTP密码 */
  179. const onCopy = () => {
  180. const clipboard = new Clipboard('#copyBtn')
  181. clipboard.on('success', () => {
  182. ElMessage.success('复制成功')
  183. clipboard.destroy()
  184. })
  185. clipboard.on('error', () => {
  186. ElMessage.error('复制失败')
  187. clipboard.destroy()
  188. })
  189. }
  190. /**申请FTP密码 */
  191. const onQuery = async () => {
  192. if (state.filter.useDate === '') {
  193. ElMessage.error('请选择密钥使用日期')
  194. }
  195. else if (state.filter.info === '') {
  196. ElMessage.error('请输入申请备注')
  197. }
  198. else {
  199. const res = await new FuelingFtpAPI().getFtpPwdofDate({ dt: state.filter.useDate }).catch()
  200. state.pwd = res.data
  201. state.msgDisplay = true
  202. state.pwdDisplay = true
  203. state.timeDisplay = true
  204. state.btnDisplay = false
  205. const date = new Date()
  206. let month = padZero(date.getMonth() + 1)
  207. let day = padZero(date.getDate())
  208. let hour = padZero(date.getHours())
  209. let minute = padZero(date.getMinutes())
  210. let second = padZero(date.getSeconds())
  211. state.filter.applyDate = date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
  212. state.filter.expirationTime = state.filter.useDate + ' 23:59:59'
  213. const name: any = await new AuthApi().getUserProfile()
  214. state.filter.name = name.data.name
  215. await new FuelingFtpAPI().insertFtpDate(state.filter)
  216. const data: any = await new FuelingFtpAPI().getFtpDate({ ...state.pageInput, filter: state.filter }).catch(() => {
  217. state.loading = false
  218. })
  219. state.total = data.data.total
  220. state.tableModel = data.data.list
  221. }
  222. }
  223. /**将Filter对象成.的连接方式*/
  224. const flattenObject = (obj, parentKey = '') => {
  225. const result = {};
  226. for (const key in obj) {
  227. if (obj.hasOwnProperty(key)) {
  228. const newKey = parentKey ? `${parentKey}.${key}` : key;
  229. if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
  230. const flattened = flattenObject(obj[key], newKey);
  231. Object.assign(result, flattened);
  232. } else {
  233. result[newKey] = obj[key];
  234. }
  235. }
  236. }
  237. return result;
  238. }
  239. /**页条数变化*/
  240. const onSizeChange = () => {
  241. init()
  242. }
  243. /**页数变化*/
  244. const onCurrentChange = () => {
  245. init()
  246. }
  247. const padZero = (num: any) => {
  248. return num < 10 ? '0' + num : num
  249. }
  250. </script>
  251. <style scoped lang="scss">
  252. .my-el-link {
  253. font-size: 12px;
  254. }
  255. .el-form .el-col.mb20 {
  256. margin: 0 !important;
  257. }
  258. .el-input,
  259. .el-select {
  260. width: 240px;
  261. }
  262. // /* 输入框标签固定四个字符宽度 */
  263. // ::v-deep .el-form-item__label {
  264. // // 字体大小144个字符,12px右间距
  265. // width: 14*4px+12px;
  266. // justify-content: start;
  267. // }
  268. /* 数据表头 设置灰色样式 */
  269. ::v-deep .el-table th.el-table__cell {
  270. background-color: #F6F6F6;
  271. }
  272. </style>