index.vue 9.8 KB

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