index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div class="TemplateManagementLists">
  3. <div class="listContent">
  4. <p class="title">模版管理</p>
  5. <p class="buttonLists">
  6. <Button type="primary" @click="searchData.page = 1;queryLists()">查询</Button>
  7. <Button type="fcdefault" :disabled="listsStatus === 1" @click="addTemplate">新建模板</Button>
  8. <Button type="fcdefault" v-if="listsStatus === 0" @click="templateMigration">模版迁移</Button>
  9. <Button type="fcdefault" v-if="listsStatus === 1" @click="removeMigration">取消迁移</Button>
  10. <Button type="fcdefault" v-if="listsStatus === 1" @click="perform">执行</Button>
  11. <Button type="fcdefault" v-if="listsStatus === 1" @click="performAll">执行全部</Button>
  12. </p>
  13. <Alert show-icon closable v-if="listsStatus === 1">依次单击模板可进行多选模板</Alert>
  14. <FormItemComponent
  15. class="form"
  16. :formItemLists="formLists"
  17. :buttonType="false"
  18. @formChange="formChange"
  19. ></FormItemComponent>
  20. <StandardTable
  21. class="table"
  22. :currentPage="searchData.page"
  23. :pageSize="searchData.pageSize"
  24. :pageSizeOpts="[20,40,60,80]"
  25. :total="total"
  26. :showTable="false"
  27. :standardTableEvent="standardTableEvent"
  28. >
  29. </StandardTable>
  30. <div class="list">
  31. <FormItemComponent
  32. class="listsForm"
  33. :formItemLists="listsConfig"
  34. :buttonType="false"
  35. :readonly="listsStatus === 1"
  36. ></FormItemComponent>
  37. <div class="noData" v-if="listsConfig.length == 0" >
  38. <span>
  39. 暂无模版
  40. </span>
  41. </div>
  42. </div>
  43. </div>
  44. <!-- 模版迁移弹窗 -->
  45. <Modal
  46. v-model="migrationModel"
  47. title="模版迁移"
  48. mask
  49. :width="440"
  50. :mask-closable="false"
  51. >
  52. <div class="migrationModelContent">
  53. <p>
  54. <Input v-model="serverUrl" placeholder="请输入目标服务器地址" style="width: 320px" />
  55. </p>
  56. </div>
  57. <p slot="footer">
  58. <Button :loading="performloading" @click="migrationModel = false">取消</Button>
  59. <Button :loading="performloading" type="primary" @click="performConfirm">确定</Button>
  60. </p>
  61. </Modal>
  62. </div>
  63. </template>
  64. <script>
  65. import FormItemComponent from '@/components/FormItemComponent';
  66. import ItemComponent from '@/components/ItemComponent';
  67. import StandardTable from '@/components/StandardTable';
  68. import listModalComponent from '@/components/listModalComponent'
  69. // import router from '../config/router.config'
  70. import { mapMutations,mapState } from 'vuex';
  71. export default {
  72. name:'TemplateManagementLists',
  73. components:{FormItemComponent,StandardTable},
  74. data () {
  75. return {
  76. // 状态 0为搜索状态,1为模版迁移状态
  77. listsStatus:0,
  78. //表单配置
  79. formLists:[
  80. {
  81. row:1,
  82. col:1,
  83. component:ItemComponent,
  84. item:{
  85. type:'input',
  86. title:'模型名称',
  87. filed:'name',
  88. event:{
  89. 'keydown': (event) => {
  90. if(event.keyCode === 13){
  91. this.searchData.page = 1
  92. this.queryLists()
  93. }
  94. }
  95. }
  96. }
  97. },
  98. {
  99. row:1,
  100. col:1,
  101. component:ItemComponent,
  102. item:{
  103. type:'select',
  104. title:'模版状态',
  105. filed:'status',
  106. options: [
  107. { value: 1, label: '已发布'},
  108. { value: 0, label: '未发布'},
  109. { value: 2, label: '已停用'}
  110. ],
  111. props:{
  112. multiple: true,
  113. multipleType: true
  114. },
  115. value:[0,1]
  116. }
  117. },
  118. {
  119. row:1,
  120. col:1,
  121. component:ItemComponent,
  122. item:{
  123. type:'DatePicker',
  124. title:'创建时间',
  125. filed:'createTime',
  126. value:[]
  127. }
  128. }
  129. ],
  130. //查询条件
  131. searchData:{
  132. page:1,
  133. pageSize:20,
  134. createTime:[],
  135. status: [0,1]
  136. },
  137. //分页数据
  138. total:0,
  139. standardTableEvent:{
  140. 'on-change':(page) => {
  141. this.searchData.page = page
  142. this.queryLists()
  143. },
  144. 'on-page-size-change':(pageSize) => {
  145. this.searchData.page = 1
  146. this.searchData.pageSize = pageSize
  147. this.queryLists()
  148. }
  149. },
  150. listsConfig:[ //列表数据
  151. ],
  152. // 迁移数据
  153. selectModal:[], //选中的迁移模版
  154. migrationModel:false, //控制模版迁移弹窗
  155. serverUrl:null, //目标服务地址
  156. migrationType:null, //0为执行 1为执行全部
  157. performloading:false
  158. }
  159. },
  160. computed:{
  161. ...mapState({
  162. currentMenu:(state) =>{
  163. return state.currentMenu
  164. }
  165. })
  166. },
  167. watch:{
  168. listsStatus () {
  169. if(this.listsStatus === 0){
  170. this.selectModal = []
  171. }
  172. }
  173. },
  174. methods:{
  175. ...mapMutations(['currentChange','changeKeepAliveArray']),
  176. formChange (data) { //表单数据修改时,修改searchData数据
  177. if(data.status){
  178. this.formLists[0].item.value = data.name
  179. this.formLists[1].item.value = data.status
  180. this.formLists[2].item.value = data.createTime
  181. // this.formLists = this.formLists.concat([])
  182. }
  183. this.searchData = Object.assign({},this.searchData,data)
  184. if(Object.prototype.toString.call(this.searchData.status) === '[object Array]' && this.searchData.status.length === 0){
  185. delete this.searchData.searchStatus
  186. delete this.searchData.status
  187. }
  188. // this.queryLists()
  189. },
  190. queryLists () { //查询列表
  191. if(this.searchData.status && this.searchData.status.indexOf('bSelect-all') >= 0){
  192. this.searchData.searchStatus = []
  193. }else{
  194. this.searchData.searchStatus = this.searchData.status
  195. }
  196. if(this.searchData.createTime && this.searchData.createTime[0] && this.searchData.createTime[1]){
  197. this.searchData.startTime = new Date(this.searchData.createTime[0]).format('yyyy-MM-dd hh:mm')
  198. this.searchData.endTime = new Date(this.searchData.createTime[1]).format('yyyy-MM-dd hh:mm')
  199. }else{
  200. this.searchData.startTime = ''
  201. this.searchData.endTime = ''
  202. }
  203. let obj = Object.assign({},this.searchData)
  204. delete obj.createTime
  205. delete obj.status
  206. this.$network.post('/p/cs/module/search', obj).then((res) => {
  207. if(res.data.resultCode !== 0){
  208. return
  209. }
  210. let data = res.data.data
  211. this.total = data.total
  212. this.listsConfig = data.records.reduce((arr,item) => {
  213. let items = {
  214. event:{
  215. queryLists:() => {
  216. this.queryLists()
  217. }
  218. }
  219. }
  220. items = Object.assign(items,item)
  221. arr.push({
  222. row:1,
  223. col:1,
  224. component:listModalComponent,
  225. item:items
  226. })
  227. return arr
  228. },[])
  229. });
  230. },
  231. addTemplate () { //新建模版
  232. this.changeKeepAliveArray(['TemplateManagementLists'])
  233. // router.push({ path: '/TemplateManagementNew/-1' })
  234. this.currentChange({
  235. path:'/TemplateManagementLists'
  236. });
  237. },
  238. templateMigration () { //模版迁移
  239. this.listsStatus = 1
  240. },
  241. removeMigration () { //取消迁移
  242. this.listsStatus = 0
  243. },
  244. modalClick (event) { //模版点击
  245. let value = event.detail.value
  246. let items = event.detail.items
  247. if(value){
  248. this.selectModal.push(items.id)
  249. }else{
  250. this.selectModal.splice(this.selectModal.findIndex(item => item === items.id), 1)
  251. }
  252. },
  253. perform () { //执行迁移
  254. if(this.selectModal.length === 0){
  255. this.$Modal.fcWarning({
  256. title:'警告',
  257. content:'请选择需要迁移的模版!',
  258. mask:true
  259. })
  260. return
  261. }
  262. this.migrationType = 0
  263. this.serverUrl = null
  264. this.migrationModel = true
  265. },
  266. performAll () { //迁移全部
  267. this.migrationType = 1
  268. this.serverUrl = null
  269. this.migrationModel = true
  270. },
  271. performConfirm () { //模版迁移确认
  272. let obj = {}
  273. if(!(this.serverUrl.startsWith('http://') || this.serverUrl.startsWith('https://'))){
  274. this.$Modal.fcWarning({
  275. title:'警告',
  276. content:'目标服务器地址必须以http://或者https://开头',
  277. mask:true
  278. })
  279. return
  280. }
  281. this.performloading = true
  282. if(this.migrationType === 0){ //执行选中模版
  283. obj = {
  284. moduleIds:this.selectModal.join(',')
  285. }
  286. }else{ //执行所有模版
  287. if(this.searchData.createTime && this.searchData.createTime[0] && this.searchData.createTime[1]){
  288. this.searchData.startTime = new Date(this.searchData.createTime[0]).format('yyyy-MM-dd hh:mm')
  289. this.searchData.endTime = new Date(this.searchData.createTime[1]).format('yyyy-MM-dd hh:mm')
  290. }else{
  291. this.searchData.startTime = ''
  292. this.searchData.endTime = ''
  293. }
  294. obj = Object.assign({},this.searchData)
  295. }
  296. obj.url = this.serverUrl
  297. this.$network.post('/p/cs/module/migrate', obj)
  298. .then((res) => {
  299. if(res.data.resultCode === 0){
  300. this.$Modal.fcSuccess({
  301. title:'成功',
  302. content:res.data.resultMsg,
  303. onOk: () => {
  304. this.queryLists()
  305. this.listsStatus = 0
  306. this.migrationModel = false
  307. this.performloading = false
  308. }
  309. })
  310. }else{
  311. this.performloading = false
  312. }
  313. })
  314. }
  315. },
  316. created () {
  317. //判断首页跳转状态,修改查询条件
  318. let status = Number(this.$route.query.status)
  319. if(status){
  320. this.searchData.status = [status]
  321. this.formLists[1].item.value = [status]
  322. this.formLists = this.formLists.concat([])
  323. }
  324. this.queryLists()
  325. },
  326. mounted () {
  327. // 监听modal的点击事件
  328. window.addEventListener('modalClick',this.modalClick)
  329. },
  330. beforeDestroy () {
  331. window.removeEventListener('modalClick', this.modalClick);
  332. },
  333. activated () {
  334. this.queryLists()
  335. }
  336. }
  337. </script>
  338. <style lang="less" >
  339. .TemplateManagementLists{
  340. display: flex;
  341. flex-direction: column;
  342. .listContent{
  343. background: white;
  344. flex: 1;
  345. padding: 16px;
  346. display: flex;
  347. flex-direction: column;
  348. overflow: hidden;
  349. .title{
  350. font-size:18px;
  351. font-family:PingFangSC-Medium;
  352. font-weight:500;
  353. color:rgba(81,90,110,1);
  354. line-height:24px;
  355. margin-bottom: 16px;
  356. }
  357. .buttonLists{
  358. margin-bottom: 10px;
  359. >button{
  360. width: 90px;
  361. margin-right: 10px;
  362. }
  363. }
  364. .form{
  365. margin-bottom: 16px;
  366. }
  367. .list{
  368. flex: 1;
  369. margin-right: -16px;
  370. overflow: auto;
  371. position: relative;
  372. .listsForm{
  373. border: none;
  374. padding: 0;
  375. margin-left: 5px;
  376. margin-top: 5px;
  377. .FormItemComponent-item{
  378. margin-right: 16px;
  379. margin-bottom: 20px;
  380. }
  381. }
  382. .noData{
  383. position: absolute;
  384. top: 50%;
  385. left: 50%;
  386. width: 280px;
  387. height: 292px;
  388. margin-top: -146px;
  389. margin-left: -140px;
  390. background-image: url('~@/assets/images/nodata.png');
  391. background-size: cover;
  392. >span{
  393. position: absolute;
  394. bottom: 40px;
  395. left: 20px;
  396. display: inline-block;
  397. width: 240px;
  398. height: 40px;
  399. text-align: center;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .migrationModelContent{
  406. height: 115px;
  407. padding: 30px 44px 17px 44px;
  408. box-sizing: border-box;
  409. }
  410. </style>