apis.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <a-card>
  3. <a-row justify="space-between" >
  4. <a-col>
  5. <a-space>
  6. </a-space>
  7. </a-col>
  8. <a-col>
  9. <a-tag color="blue" v-if="state.appId" style="scale: 1.2;" >appid: {{state.appId}}</a-tag>
  10. <a-button v-else type="primary" @click="openModal('add', {})" >创建Appid</a-button>
  11. </a-col>
  12. </a-row>
  13. <a-table
  14. :columns="columns"
  15. :loading="state.loading"
  16. :data-source="state.dataSource"
  17. style="margin-top: 20px;"
  18. :pagination="false"
  19. >
  20. <template #bodyCell="{column, record}" >
  21. <template v-if="column.key === 'createAt'" >
  22. <div>{{ dayjs(record.createAt).format('YYYY/MM/DD HH:mm:ss')}}</div>
  23. </template>
  24. <template v-if="column.key === 'action'" >
  25. <a-space>
  26. <!-- <a @click="openModal('update', record)" >编辑</a> -->
  27. <a @click="delApiId(record)" >删除</a>
  28. </a-space>
  29. </template>
  30. </template>
  31. </a-table>
  32. </a-card>
  33. <modal-pro
  34. title="创建Appid"
  35. :open="state.visible"
  36. @cancel="state.visible = false"
  37. @ok="ok"
  38. >
  39. <a-form :labelCol="{span: 6}" :wrapperCol="{span: 14}" >
  40. <a-form-item label="appid" v-bind="validateInfos.appId" >
  41. <a-input allowClear v-model:value="appidState.appId" />
  42. </a-form-item>
  43. <a-form-item label="appid名称" v-bind="validateInfos.appIdLabel" >
  44. <a-input allowClear v-model:value="appidState.appIdLabel" />
  45. </a-form-item>
  46. </a-form>
  47. </modal-pro>
  48. </template>
  49. <script lang='ts' setup >
  50. import { DataController } from '@/controller/iot/data'
  51. import { Form } from 'ant-design-vue'
  52. import { onMounted, reactive, ref } from 'vue'
  53. import { useSchedulerOnce } from '@/hooks/index'
  54. import dayjs from 'dayjs'
  55. const useForm = Form.useForm
  56. const columns = [
  57. {
  58. title: 'appId名称',
  59. dataIndex: 'appIdLabel'
  60. },
  61. {
  62. title: 'appId',
  63. dataIndex: 'appId'
  64. },
  65. {
  66. title: '创建时间',
  67. dataIndex: 'createAt',
  68. key: 'createAt'
  69. },
  70. {
  71. title: '操作',
  72. key: 'action'
  73. }
  74. ]
  75. const queryParams = reactive({
  76. page: 1,
  77. pageSize: 10,
  78. total: 0,
  79. apiLabel: ''
  80. })
  81. const state = reactive({
  82. loading: false,
  83. appId: '',
  84. visible: false,
  85. detailVisible: false,
  86. openApiDetail: {},
  87. dataSource: [],
  88. spnningLoading: false
  89. })
  90. const appidState = reactive({
  91. id: '',
  92. appId: '',
  93. appIdLabel: ''
  94. })
  95. const { resetFields, validate, validateInfos } = useForm(appidState, {
  96. appId: [{ required: true, message: '请填写appid' }],
  97. appIdLabel: [{ required: true, message: '请填写id名称' }]
  98. })
  99. const delApiId = async (record: any) => {
  100. await DataController.delAppIdById(record.id)
  101. getAppid()
  102. }
  103. const openDetailModel = (record: any) => {
  104. state.openApiDetail = record
  105. state.detailVisible = true
  106. useSchedulerOnce(() => {
  107. state.spnningLoading = false
  108. console.log('state.spnningLoading:', state.spnningLoading)
  109. }, 1000)
  110. }
  111. const opraState = ref<'add' | 'update'>('add')
  112. const openModal = (type: 'add' | 'update', record: any) => {
  113. state.visible = true
  114. opraState.value = type
  115. resetFields(record)
  116. }
  117. const ok = async () => {
  118. validate().then(async () => {
  119. opraState.value === 'add' ? await DataController.postAppId(appidState) : await DataController.updateAppId(appidState)
  120. state.visible = false
  121. getAppid()
  122. })
  123. }
  124. const getAppid = async () => {
  125. const { data } = await DataController.getAppId()
  126. state.dataSource = data
  127. }
  128. onMounted(() => {
  129. getAppid()
  130. })
  131. </script>
  132. <style lang='less' scoped >
  133. </style>