index.vue 8.8 KB

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