index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div class="ruleSetList">
  3. <div class="tabBody">
  4. <a-tabs v-model="tabKey" @change="tabChange">
  5. <a-tab-pane key="1" tab="规则管理"></a-tab-pane>
  6. <a-tab-pane key="2" tab="运行记录" ></a-tab-pane>
  7. </a-tabs>
  8. </div>
  9. <div class="tableBody">
  10. <div class="opt" v-if="tabKey=='1'">
  11. <a-button type='primary' @click='createNewRule'>新建空白规则模板</a-button>
  12. <p class="title">已创建的规则模板</p>
  13. </div>
  14. <div class="opts" v-else>
  15. <a-input-search placeholder="请输入规则id" style="width:350px" v-model="rulesId" enter-button @search="onSearch" />
  16. </div>
  17. <div class="table">
  18. <a-table
  19. size="middle"
  20. :columns="columns"
  21. :dataSource="data"
  22. bordered
  23. id="outTable"
  24. :pagination="ipagination"
  25. :scroll="{ x: scrollX }"
  26. :loading="loading"
  27. @change="sort"
  28. style="word-break: break-all;"
  29. >
  30. <span slot="status" slot-scope="text,record">
  31. <a-spin :spinning="record.spin" size="small" >
  32. <div class="spin-content">
  33. <a-switch size="default" :checked=text @change="switchChange(text,record)"/>
  34. </div>
  35. </a-spin>
  36. <!-- <a-switch size="default" :checked=text @change="switchChange(text,record)"/> -->
  37. </span>
  38. <span slot="mediaType" slot-scope="text">
  39. {{text|handleMediaType}}
  40. </span>
  41. <span slot="processMethod" slot-scope="text">
  42. {{text=='SEND'?'仅发送通知':'发送并关停组'}}
  43. </span>
  44. <span slot="options" slot-scope="text,record">
  45. <a href="javascript:;" @click="editRule(record)">编辑</a>
  46. <a-divider type="vertical" />
  47. <a-popconfirm
  48. :title="`当前模板关联账户个数为${relationCount},确定删除吗?`"
  49. @confirm="deleteRule(record)"
  50. >
  51. <a href="javascript:;" @click.stop="showRelativeCount(record)">删除</a>
  52. </a-popconfirm>
  53. </span>
  54. </a-table>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import moment from 'moment';
  61. import { getAction, postAction, downFile, downFilePost } from '@/api/manage';
  62. let existColumns=[
  63. // {
  64. // title: '运行/暂停',
  65. // dataIndex: 'status',
  66. // align: 'center',
  67. // width:100,
  68. // key: 'status',
  69. // scopedSlots: { customRender: 'status' }
  70. // },
  71. {
  72. title: '模板名称',
  73. dataIndex: 'templateName',
  74. align: 'center',
  75. key: 'templateName',
  76. scopedSlots: { customRender: 'templateName' }
  77. },
  78. {
  79. title: '应用媒体',
  80. dataIndex: 'mediaType',
  81. align: 'center',
  82. key: 'mediaType',
  83. scopedSlots: { customRender: 'mediaType' }
  84. },
  85. {
  86. title: '结果操作',
  87. dataIndex: 'processMethod',
  88. align: 'center',
  89. key: 'processMethod',
  90. scopedSlots: { customRender: 'processMethod' }
  91. },
  92. {
  93. title: '创建者',
  94. dataIndex: 'createrName',
  95. align: 'center',
  96. key: 'createrName',
  97. scopedSlots: { customRender: 'createrName' }
  98. },
  99. {
  100. title: '操作',
  101. dataIndex: 'options',
  102. align: 'center',
  103. key: 'options',
  104. scopedSlots: { customRender: 'options' }
  105. },
  106. ]
  107. let recordsColumns=[
  108. {
  109. title: '模板名称',
  110. dataIndex: 'templateName',
  111. align: 'center',
  112. key: 'templateName',
  113. scopedSlots: { customRender: 'templateName' }
  114. },
  115. {
  116. title: '应用媒体',
  117. dataIndex: 'mediaType',
  118. align: 'center',
  119. key: 'mediaType',
  120. scopedSlots: { customRender: 'mediaType' }
  121. },
  122. {
  123. title: '运行对象',
  124. dataIndex: 'accountName',
  125. align: 'center',
  126. key: 'accountName',
  127. scopedSlots: { customRender: 'accountName' }
  128. },
  129. {
  130. title: '满足条件',
  131. dataIndex: 'alarmCondition',
  132. align: 'center',
  133. key: 'alarmCondition',
  134. scopedSlots: { customRender: 'alarmCondition' }
  135. },
  136. {
  137. title: '运行结果',
  138. dataIndex: 'processMethod',
  139. align: 'center',
  140. key: 'processMethod',
  141. scopedSlots: { customRender: 'processMethod' }
  142. },
  143. ]
  144. export default {
  145. data() {
  146. return {
  147. relationCount:2,
  148. tabKey:"1",
  149. rulesId:undefined,
  150. data:[],
  151. columns:[...existColumns],
  152. scrollX:0,
  153. loading:false,
  154. ipagination: {
  155. current: 1,
  156. pageSize: 10,
  157. // pageSizeOptions: ['10', '20', '30'],
  158. showTotal: (total, range) => {
  159. return range[0] + "-" + range[1] + " 共" + total + "条"
  160. },
  161. showQuickJumper: true,
  162. showSizeChanger:true,
  163. pageSizeOptions: ['10', '30', '50'],
  164. total: 0,
  165. onChange: (current, pageSize) => {
  166. // 切换分页时的回调,
  167. // 当在页面定义change事件时,切记要把此处的事件清除,因为这两个事件重叠了,可能到时候会导致一些莫名的bug
  168. this.ipagination.current = current;
  169. this.ipagination.pageSize= pageSize;
  170. }
  171. },
  172. url:{
  173. list:'/ruleTemplate/list',
  174. delete:'/ruleTemplate/delete',
  175. getRelationAccountById:'/ruleAccountTemplate/getRelationAccountById',
  176. edit:'',
  177. },
  178. }
  179. },
  180. methods: {
  181. moment,
  182. onSearch(value) {
  183. console.log(value);
  184. },
  185. tabChange(key){
  186. console.log(key);
  187. let url=''
  188. if(key=='1'){
  189. this.columns=[...existColumns]
  190. url=this.url.existUrl
  191. }else{
  192. this.columns=[...recordsColumns]
  193. url=this.url.resultRecordUrl
  194. }
  195. this.getTableListHttp(url)
  196. },
  197. createNewRule(){
  198. this.$router.push('/earlyWarningRules/configRules')
  199. },
  200. sort(pagination, filters, sorter, { currentDataSource }){
  201. this.ipagination.current=pagination.current;
  202. this.ipagination.pageSize=pagination.pageSize;
  203. let url=this.tabKey=='1'?this.url.existUrl:this.url.resultRecordUrl
  204. this.getTableListHttp(url)
  205. },
  206. editRule(record){
  207. console.log(record);
  208. this.$router.push(`/earlyWarningRules/configRules?id=${record.id}&edit=true`)
  209. },
  210. // recordsRule(record){
  211. // console.log(record);
  212. // },
  213. showRelativeCount(record){
  214. getAction(this.url.getRelationAccountById,{
  215. id:record.id
  216. }).then(res=>{
  217. console.log(res)
  218. if(res.success){
  219. this.relationCount=res.result.relationCount
  220. // getAction(this.url.delete,{
  221. // id:record.id
  222. // }).then(res=>{
  223. // console.log(res);
  224. // if(res.success){
  225. // this.getTableListHttp(this.url.list)
  226. // }else{
  227. // this.$message.error('删除失败')
  228. // }
  229. // })
  230. }
  231. })
  232. },
  233. deleteRule(record){
  234. console.log(record);
  235. getAction(this.url.getRelationAccountById,{
  236. id:record.id
  237. }).then(res=>{
  238. console.log(res)
  239. if(res.success){
  240. // getAction(this.url.delete,{
  241. // id:record.id
  242. // }).then(res=>{
  243. // console.log(res);
  244. // if(res.success){
  245. // this.getTableListHttp(this.url.list)
  246. // }else{
  247. // this.$message.error('删除失败')
  248. // }
  249. // })
  250. }
  251. })
  252. },
  253. switchChange(text,record){
  254. console.log(text,record);
  255. record.spin=true;
  256. let eventRuleStatus='1'
  257. if(text){
  258. eventRuleStatus='0'
  259. }else{
  260. eventRuleStatus='1';
  261. }
  262. postAction('/alarm/alarmEventRule/edit',{
  263. eventRuleId:record.eventRuleId,
  264. eventRuleStatus,
  265. }).then(res=>{
  266. console.log(res);
  267. record.spin=false;
  268. if(res.success){
  269. // this.getTableListHttp()
  270. if(text){
  271. record.status=false
  272. eventRuleStatus='0'
  273. }else{
  274. record.status=true
  275. eventRuleStatus='1';
  276. }
  277. }else{
  278. this.$message.error('修改失败')
  279. // this.getTableListHttp()
  280. }
  281. })
  282. },
  283. getTableListHttp(url){
  284. this.data=[];
  285. this.loading=true;
  286. // let url='/alarm/alarmEventRule/list'
  287. getAction(url,{
  288. pageNo:this.ipagination.current,
  289. pageSize:this.ipagination.pageSize
  290. }).then(res=>{
  291. console.log(res);
  292. this.loading=false;
  293. if(res.success){
  294. this.data=res.result.records.map(item=>{
  295. return {
  296. ...item,
  297. status:item.eventRuleStatus=='1'?true:false,
  298. spin:false,
  299. }
  300. })
  301. this.ipagination.total=res.result.total
  302. }
  303. })
  304. }
  305. },
  306. mounted(){
  307. this.getTableListHttp(this.url.list)
  308. },
  309. activated(){
  310. this.getTableListHttp(this.url.list)
  311. },
  312. filters:{
  313. handleMediaType(val){
  314. switch (val) {
  315. case 1:
  316. return '头条'
  317. break;
  318. case 2:
  319. return '快手'
  320. break;
  321. case 3:
  322. return '头条内广'
  323. break;
  324. case 4:
  325. return '快手内广'
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped>
  335. .ruleSetList{
  336. background: white;
  337. padding: 20px;
  338. .tabBody{
  339. margin-bottom: 5px;
  340. }
  341. .tableBody{
  342. .opt{
  343. .title{
  344. margin: 15px 0;
  345. height: 57px;
  346. font-size: 16px;
  347. color: #333;
  348. line-height: 57px;
  349. background: #ffffff;
  350. padding-left: 15px;
  351. border-radius: 4px 4px 0 0;
  352. font-weight: 600;
  353. border-bottom: 1px solid #DADFE3;
  354. }
  355. }
  356. .opts{
  357. margin-bottom: 15px;
  358. }
  359. }
  360. }
  361. </style>