notice.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <a-card>
  3. <a-row>
  4. <a-col span="12">
  5. <a-form layout="inline" >
  6. <a-form-item label="通知名称" >
  7. <a-input v-model:value="queryParamsState.label" placeholder="请输入通知名称"/>
  8. </a-form-item>
  9. <a-form-item label='通知数据来源' >
  10. <a-select
  11. style="width: 170px"
  12. v-model:value="queryParamsState.source"
  13. >
  14. <a-select-option
  15. v-for="item in sourceList"
  16. :key="item.key"
  17. :value="item.key"
  18. >
  19. {{item.label}}
  20. </a-select-option>
  21. </a-select>
  22. </a-form-item >
  23. <a-form-item>
  24. <a-button type="primary" @click="getNoticePage">搜索</a-button>
  25. </a-form-item>
  26. </a-form>
  27. </a-col>
  28. <a-col span="12" >
  29. <a-row justify="end" >
  30. <a-button type="primary" @click="openModal('add')" >新增</a-button>
  31. </a-row>
  32. </a-col>
  33. </a-row>
  34. <a-table
  35. style="margin-top: 20px;"
  36. :columns="columns"
  37. :data-source="state.dataSource"
  38. :loading="state.loading"
  39. :pagination="queryParamsState"
  40. @change="changePage"
  41. >
  42. <template #bodyCell="{column, record}">
  43. <template v-if="column.key === 'status'" >
  44. <a-switch
  45. @click="changeStatus(record)"
  46. v-model:checked="record.status"
  47. checked-children="运行中"
  48. un-checked-children="已关闭"
  49. />
  50. </template>
  51. <template v-if="column.key === 'action'" >
  52. <a-space>
  53. <a @click="openModal('update', record.id)" >编辑</a>
  54. <a-popconfirm
  55. title="确实要删除吗?"
  56. ok-text="确定"
  57. cancel-text="取消"
  58. @confirm="delNotice(record.id)"
  59. >
  60. <a>删除</a>
  61. </a-popconfirm>
  62. </a-space>
  63. </template>
  64. </template>
  65. </a-table>
  66. </a-card>
  67. <modal-pro
  68. :label="modalTitle"
  69. :visible="state.visible"
  70. destroyOnClose
  71. @cancel="state.visible = false"
  72. @ok="ok"
  73. >
  74. <a-form :label-col="{span: 4}" :wrapper-col="{span: 14}">
  75. <a-form-item label="任务名称" v-bind="validateInfos.taskLabel">
  76. <a-input v-model:value="modalRef.taskLabel" />
  77. </a-form-item>
  78. <a-form-item label="任务描述" >
  79. <a-input v-model:value="modalRef.taskDescription" />
  80. </a-form-item>
  81. <a-form-item label="选择产品" >
  82. <a-select
  83. placeholder="请选择产品"
  84. v-model:value="modalRef.taskConfig.modelId"
  85. >
  86. <a-select-option
  87. v-for="model in state.modelList"
  88. :key="model.id"
  89. :value="model.id"
  90. >
  91. {{model.modelLabel}}
  92. </a-select-option>
  93. </a-select>
  94. </a-form-item>
  95. <a-form-item label="选择设备" >
  96. <a-select
  97. placeholder="请选择产品"
  98. v-model:value="modalRef.taskConfig.deviceId"
  99. >
  100. <a-select-option
  101. v-for="device in state.deviceList"
  102. :key="device.id"
  103. :value="device.id"
  104. >
  105. {{device.deviceLabel}}
  106. </a-select-option>
  107. </a-select>
  108. </a-form-item>
  109. <a-form-item label="任务类型" v-bind="validateInfos.taskType">
  110. <a-select v-model:value="modalRef.taskConfig.taskType" >
  111. <a-select-option
  112. :value="item"
  113. v-for="item in TaskController.taskTypeList"
  114. :key="item"
  115. >
  116. {{TaskController.taskTypeMap.get(item)?.label }}
  117. </a-select-option>
  118. </a-select>
  119. </a-form-item>
  120. <span v-if="modalRef.taskConfig.taskType === 'DEVICE_CMD'" >
  121. <a-form-item label="选择命令" >
  122. <a-select
  123. style="width: 170px;"
  124. v-model:value="modalRef.taskConfig.cmdId"
  125. >
  126. <a-select-option
  127. v-for="cmdItem in state.cmdList"
  128. :key="cmdItem.id"
  129. :value="cmdItem.id"
  130. >
  131. {{cmdItem.cmdLabel}}
  132. </a-select-option>
  133. </a-select>
  134. </a-form-item>
  135. <a-form-item label="命令参数" >
  136. <div
  137. v-for="(item, index) in modalRef.taskConfig.cmdParameters"
  138. :key="index"
  139. style="margin-bottom: 10px;"
  140. >
  141. <a-input-group compact >
  142. <a-input placeholder="key" disabled v-model:value="item.paramLabel" style="width: 50%" />
  143. <a-input placeholder="value" v-model:value="item.dataUnit" style="width: 50%" />
  144. </a-input-group>
  145. </div>
  146. </a-form-item>
  147. </span>
  148. <span v-if="modalRef.taskConfig.taskType === 'DEVICE_MSG'" >
  149. <a-form-item label="主题" >
  150. <a-input v-model:value="modalRef.taskConfig.topic" />
  151. </a-form-item>
  152. <a-form-item label="消息名称" >
  153. <a-input v-model:value="modalRef.taskConfig.msgLabel" />
  154. </a-form-item>
  155. <a-form-item label="消息内容" >
  156. <a-textarea :auto-size="{ minRows: 2, maxRows: 5 }" v-model:value="modalRef.taskConfig.msgPayload" />
  157. </a-form-item>
  158. </span>
  159. </a-form>
  160. </modal-pro>
  161. </template>
  162. <script lang="ts" setup >
  163. import { reactive, onMounted, computed } from 'vue'
  164. import { SysController } from '@/controller'
  165. import { Form } from 'ant-design-vue'
  166. const useForm = Form.useForm
  167. const columns = [
  168. {
  169. title: 'id',
  170. dataIndex: 'id'
  171. },
  172. {
  173. title: '通知名称',
  174. dataIndex: 'label',
  175. key: 'label'
  176. },
  177. {
  178. title: '通知数据来源',
  179. dataIndex: 'source',
  180. key: 'source'
  181. },
  182. {
  183. title: '状态',
  184. dataIndex: 'status',
  185. key: 'status'
  186. },
  187. {
  188. title: '操作',
  189. dataIndex: 'action',
  190. key: 'action'
  191. }
  192. ]
  193. const sourceList = [{ key: 0, label: '通知' }, { key: 1, label: '告警' }]
  194. const queryParamsState = reactive({
  195. page: 1,
  196. pageSize: 10,
  197. label: '',
  198. source: ''
  199. })
  200. const state = reactive({
  201. dataSource: [],
  202. loading: false,
  203. visible: false,
  204. opraState: 'add',
  205. noticeId: ''
  206. })
  207. const modalRef = reactive({
  208. label: '',
  209. source: 0,
  210. status: false
  211. })
  212. const modalTitle = computed(() => state.opraState === 'add' ? '新增通知' : '编辑通知')
  213. const { resetFields, validate, validateInfos } = useForm(modalRef, reactive({
  214. label: [{ required: true, message: '请填写通知名称' }]
  215. }))
  216. const ok = () => {
  217. }
  218. const openModal = (opraState: 'add' | 'update', id = '') => {
  219. state.opraState = opraState
  220. state.visible = true
  221. state.noticeId = id
  222. if (opraState === 'update') {
  223. getNoticeById()
  224. }
  225. }
  226. const changePage = ({ current }) => {
  227. queryParamsState.page = current
  228. getNoticePage()
  229. }
  230. const delNotice = (id: string) => SysController.delNotice(id)
  231. const changeStatus = async (record) => SysController.updateNoticeStaus({ id: record.id, status: record.status })
  232. const getNoticeById = async () => {
  233. const { data } = await SysController.noticeById(state.noticeId)
  234. resetFields(data)
  235. }
  236. const getNoticePage = async () => {
  237. state.loading = true
  238. const { data } = await SysController.noticeMethodPage(queryParamsState)
  239. state.loading = false
  240. state.dataSource = data
  241. }
  242. onMounted(() => {
  243. getNoticePage()
  244. })
  245. </script>
  246. <style lang="less" scoped >
  247. </style>