rule-detail.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <CusDialog
  3. :show="show"
  4. :title="titleCpt"
  5. @onClose="$emit('update:show', false)"
  6. width="800px"
  7. max-height="80%"
  8. @onSubmit="onSubmit"
  9. :loading="state.loading"
  10. >
  11. <div class="__cus-dialog-form">
  12. <CusForm ref="ref_form" label-width="100px">
  13. <div class="__cus-title_1">场景设定</div>
  14. <el-col :span="12">
  15. <CusFormColumn
  16. :span="24"
  17. required
  18. label="预警名称"
  19. v-model:param="state.form.name"
  20. />
  21. <CusFormColumn
  22. :span="24"
  23. required
  24. label="预警级别"
  25. v-model:param="state.form.level"
  26. link="select"
  27. :options="DictionaryStore.warningLevelList"
  28. />
  29. <CusFormColumn
  30. :span="24"
  31. required
  32. label="预警模型"
  33. v-model:param="state.modelDetail.name"
  34. :disabled="true"
  35. />
  36. </el-col>
  37. <el-col :span="12">
  38. <CusFormColumn
  39. :span="24"
  40. label="场景描述"
  41. v-model:param="state.form.description"
  42. type="textarea"
  43. :rows="6"
  44. />
  45. </el-col>
  46. <div class="__cus-title_1">参数配置</div>
  47. <div class="params-table" style="width: 100%">
  48. <CusTable
  49. :data="state.paramList"
  50. :table-head="[
  51. {value: 'name', label: '参数'},
  52. {value: 'value', label: '值'},
  53. {value: 'unit', label: '单位'},
  54. ]"
  55. :no-page="true"
  56. >
  57. <template #value-column-value="{scope}">
  58. <CusFormColumn
  59. :required="scope.row.required"
  60. class="__cus-table-form-column"
  61. :span="24"
  62. v-model:param="scope.row.value"
  63. :default-error-msg="'请输入' + scope.row.name"
  64. link="number"
  65. :placeholder="'推荐值:' + scope.row.recommendValue"
  66. />
  67. </template>
  68. </CusTable>
  69. </div>
  70. <div class="__cus-title_1" v-if="state.modelDetail.areaConfig != 0 || state.modelDetail.allowAreaConfig != 0">区域配置</div>
  71. <el-col :span="24" v-if="state.modelDetail.areaConfig != 0">
  72. <el-row>
  73. <CusFormColumn
  74. label-width="140px"
  75. :required="state.modelDetail.areaConfig == 2"
  76. :span="20"
  77. label="预警区域选择"
  78. v-model:param="state.areaIds.warning"
  79. link="select"
  80. multiple
  81. :options="DictionaryStore.warningAreaList.filter(v => !state.areaIds.white.includes(v.id))"
  82. label-key="name"
  83. value-key="id"
  84. />
  85. <el-col :span="4" v-if="state.areaIds.warning.length > 0">
  86. <div class="view-area __hover" @click="onAreaMap(state.areaIds.warning)">查看区域</div>
  87. </el-col>
  88. </el-row>
  89. </el-col>
  90. <el-col :span="24" v-if="state.modelDetail.allowAreaConfig != 0">
  91. <el-row>
  92. <CusFormColumn
  93. label-width="140px"
  94. :required="state.modelDetail.allowAreaConfig == 2"
  95. :span="20"
  96. label="白名单区域选择"
  97. v-model:param="state.areaIds.white"
  98. link="select"
  99. multiple
  100. :options="DictionaryStore.warningAreaList.filter(v => !state.areaIds.warning.includes(v.id))"
  101. label-key="name"
  102. value-key="id"
  103. />
  104. <el-col :span="4" v-if="state.areaIds.white.length > 0">
  105. <div class="view-area __hover" @click="onAreaMap(state.areaIds.white)">查看区域</div>
  106. </el-col>
  107. </el-row>
  108. </el-col>
  109. </CusForm>
  110. <areaMap v-model:show="state.areaMap.show" :transfer="state.areaMap.transfer"/>
  111. </div>
  112. </CusDialog>
  113. </template>
  114. <script setup lang="ts">
  115. import {computed, getCurrentInstance, nextTick, onMounted, reactive, ref, watch} from "vue";
  116. import {useDictionaryStore} from "@/stores";
  117. import {ElMessage, ElMessageBox} from "element-plus";
  118. import areaMap from './area-map.vue'
  119. import {warnModelDetail} from "@/api/modules/web/model";
  120. import {warnAreaQueryAll} from "@/api/modules/web/area";
  121. import {warnRuleAdd, warnRuleDetail, warnRuleEdit} from "@/api/modules/web/rule";
  122. const emit = defineEmits(['update:show', 'refresh'])
  123. const {proxy} = getCurrentInstance()
  124. const DictionaryStore = useDictionaryStore()
  125. const props = defineProps({
  126. show: {default: false},
  127. transfer: {}
  128. })
  129. const state: any = reactive({
  130. form: {},
  131. loading: false,
  132. areaIds: {
  133. warning: [],
  134. white: [],
  135. },
  136. areaMap: {
  137. show: false,
  138. transfer: {}
  139. },
  140. modelDetail: {},
  141. paramList: [],
  142. })
  143. const ref_form = ref()
  144. const titleCpt = computed(() => {
  145. let t = '查看预警规则'
  146. switch (props.transfer.mode) {
  147. case 'add': t = '新增预警规则'
  148. break
  149. case 'edit': t = '编辑预警规则'
  150. break
  151. }
  152. return t
  153. })
  154. const onSubmit = () => {
  155. ref_form.value.submit().then(() => {
  156. ElMessageBox.confirm("是否提交?", "提示", {
  157. confirmButtonText: "确定",
  158. cancelButtonText: "取消",
  159. type: "warning",
  160. } as any).then(() => {
  161. state.loading = true
  162. const params = {
  163. enabled: false,
  164. ...state.form,
  165. modelId: props.transfer.modelId,
  166. paramList: state.paramList.map(v => ({id: v.id, value: v.value})),
  167. areaTypeList: []
  168. }
  169. if (state.modelDetail.areaConfig != 0) {
  170. state.areaIds.warning.forEach(v => {
  171. params.areaTypeList.push({id: v, type: 1})
  172. })
  173. }
  174. if (state.modelDetail.allowAreaConfig != 0) {
  175. state.areaIds.white.forEach(v => {
  176. params.areaTypeList.push({id: v, type: 2})
  177. })
  178. }
  179. if (props.transfer.mode == 'add') {
  180. warnRuleAdd(params).then(res => {
  181. if (res.code == 0) {
  182. ElMessage.success('新增成功!')
  183. emit('update:show', false)
  184. emit('refresh')
  185. state.loading = false
  186. } else {
  187. ElMessage.error(res.msg)
  188. }
  189. }).catch(() => {
  190. state.loading = false
  191. })
  192. } else {
  193. warnRuleEdit(params).then(res => {
  194. if (res.code == 0) {
  195. ElMessage.success('编辑成功!')
  196. emit('update:show', false)
  197. emit('refresh')
  198. state.loading = false
  199. } else {
  200. ElMessage.error(res.msg)
  201. }
  202. }).catch(() => {
  203. state.loading = false
  204. })
  205. }
  206. }).catch(() => {})
  207. }).catch((e) => {
  208. ElMessage({
  209. message: e[0].message,
  210. grouping: true,
  211. type: 'warning',
  212. })
  213. })
  214. }
  215. const initDetail = () => {
  216. warnRuleDetail(proxy.$util.formatGetParam({id: props.transfer.id})).then(res => {
  217. if (res.code == 0) {
  218. state.form = res.data
  219. state.form.areaTypeList.forEach(v => {
  220. if (v.type == 1) {
  221. state.areaIds.warning.push(v.id)
  222. } else {
  223. state.areaIds.white.push(v.id)
  224. }
  225. })
  226. initModel(state.form.modelId)
  227. } else {
  228. ElMessage.error(res.msg)
  229. }
  230. })
  231. }
  232. const initArea = () => {
  233. warnAreaQueryAll().then(res => {
  234. DictionaryStore.initOtherDict('warningArea', res.data.map(v => {
  235. v.dictLabel = v.name
  236. v.dictValue = v.id
  237. return v
  238. }))
  239. })
  240. }
  241. watch(() => props.show, (n) => {
  242. if (n) {
  243. state.loading = true
  244. initDictionary()
  245. state.form = {}
  246. state.modelDetail = {}
  247. state.paramList = []
  248. state.areaIds.white = []
  249. state.areaIds.warning = []
  250. if (props.transfer.mode !== 'add') {
  251. initDetail()
  252. } else {
  253. initModel(props.transfer.modelId)
  254. }
  255. nextTick(() => {
  256. ref_form.value.reset()
  257. })
  258. }
  259. })
  260. const initModel = (id) => {
  261. warnModelDetail(proxy.$util.formatGetParam({id: id})).then(res => {
  262. if (res.code == 0) {
  263. state.modelDetail = res.data
  264. state.paramList = state.modelDetail.paramDictList
  265. if (props.transfer.mode != 'add') {
  266. state.paramList.forEach(v => {
  267. state.form.paramList.forEach(v2 => {
  268. if (v.id == v2.id) {
  269. v.value = v2.value
  270. }
  271. })
  272. })
  273. }
  274. state.loading = false
  275. } else {
  276. ElMessage.error(res.msg)
  277. }
  278. })
  279. }
  280. const onAreaMap = (areas) => {
  281. state.areaMap.transfer = {
  282. areas: areas
  283. }
  284. state.areaMap.show = true
  285. }
  286. onMounted(() => {
  287. initArea()
  288. })
  289. const initDictionary = () => {
  290. // DictionaryStore.initDict('format_type')
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .__cus-title_1 {
  295. margin-bottom: 20px;
  296. }
  297. .params-table {
  298. margin-bottom: 20px;
  299. }
  300. .view-area {
  301. line-height: 40px;
  302. margin-left: 20px;
  303. font-weight: 400;
  304. font-size: 16px;
  305. color: #81AFFF;
  306. }
  307. </style>