You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Model.vue 20 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <div>
  3. <div class="ui container" id="header">
  4. <el-row style="margin-top:15px;">
  5. <el-table
  6. ref="table"
  7. :data="tableData"
  8. style="min-width: 100%"
  9. row-key="ID"
  10. lazy
  11. :load="load"
  12. :tree-props="{children: 'Children', hasChildren: 'hasChildren'}"
  13. :header-cell-style="tableHeaderStyle"
  14. >
  15. <el-table-column
  16. prop="Name"
  17. label="模型名称"
  18. align="left"
  19. min-width="18%"
  20. >
  21. <template slot-scope="scope">
  22. <div class="expand-icon" v-if="scope.row.hasChildren===false">
  23. <i class="el-icon-arrow-right"></i>
  24. </div>
  25. <!-- <i class="el-icon-time"></i> -->
  26. <a class="text-over" :href="showinfoHref+scope.row.Name" :title="scope.row.Name">{{ scope.row.Name }}</a>
  27. </template>
  28. </el-table-column>
  29. <el-table-column
  30. prop="Version"
  31. label="版本"
  32. align="center"
  33. min-width="6.5%"
  34. >
  35. <template slot-scope="scope">
  36. <span class="text-over" :title="scope.row.Version">{{ scope.row.Version}}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column
  40. prop="VersionCount"
  41. label="版本数"
  42. align="center"
  43. min-width="7.5%"
  44. >
  45. <template slot-scope="scope">
  46. <span class="text-over" :title="scope.row.VersionCount">{{ scope.row.VersionCount}}</span>
  47. </template>
  48. </el-table-column>
  49. <el-table-column
  50. prop="Size"
  51. label="模型大小"
  52. align="center"
  53. min-width="10.5%"
  54. >
  55. <template slot-scope="scope">
  56. <span class="text-over">{{ renderSize(scope.row.Size)}}</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column
  60. prop="EngineName"
  61. label="AI引擎"
  62. align="center"
  63. min-width="8.5%"
  64. >
  65. <template slot-scope="scope">
  66. <span class="text-over">{{ scope.row.EngineName}}</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column
  70. prop="ComputeResource"
  71. label="计算资源"
  72. align="center"
  73. min-width="10.5%"
  74. >
  75. <template slot-scope="scope">
  76. <span class="text-over">{{ scope.row.ComputeResource}}</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column
  80. prop="CreatedUnix"
  81. label="创建时间"
  82. align="center"
  83. min-width="13.75%"
  84. >
  85. <template slot-scope="scope">
  86. {{transTime(scope.row.CreatedUnix)}}
  87. </template>
  88. </el-table-column>
  89. <el-table-column
  90. prop="UserName"
  91. label="创建者"
  92. align="center"
  93. min-width="6.75%"
  94. >
  95. <template slot-scope="scope">
  96. <a :href="!scope.row.UserName? '#':'/'+scope.row.UserName" :title="scope.row.UserName||defaultAvatarName">
  97. <img class="ui avatar image" :src="scope.row.UserRelAvatarLink||defaultAvatar">
  98. </a>
  99. </template>
  100. </el-table-column>
  101. <el-table-column label="操作" min-width="18%" align="center">
  102. <template slot-scope="scope">
  103. <div class="space-around">
  104. <a :style="{visibility:!scope.row.Children ? 'visible':'hidden'}" :class="{'disabled':!scope.row.IsCanOper}" @click="showcreateVue(scope.row.Name,scope.row.Version,scope.row.Label)">创建新版本</a>
  105. <a :href="loadhref+scope.row.ID" :class="{'disabled':!scope.row.IsCanOper}">下载</a>
  106. <a :class="{'disabled':!scope.row.IsCanDelete}" @click="deleteModel(scope.row.ID,scope.row.cName)">删除</a>
  107. </div>
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. </el-row>
  112. <div class="ui container" style="margin-top:50px;text-align:center">
  113. <el-pagination
  114. background
  115. @size-change="handleSizeChange"
  116. @current-change="handleCurrentChange"
  117. :current-page="currentPage"
  118. :page-sizes="[5,10,15]"
  119. :page-size="pageSize"
  120. layout="total, sizes, prev, pager, next, jumper"
  121. :total="totalNum">
  122. </el-pagination>
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. <script>
  128. const {_AppSubUrl, _StaticUrlPrefix, csrf} = window.config;
  129. export default {
  130. components: {
  131. },
  132. data() {
  133. return {
  134. currentPage:1,
  135. pageSize:10,
  136. totalNum:0,
  137. params:{page:0,pageSize:10},
  138. tableData: [],
  139. url:'',
  140. isLoading:true,
  141. loadNodeMap:new Map(),
  142. submitId:{},
  143. defaultAvatar:'/user/avatar/Ghost/-1',
  144. defaultAvatarName:'Ghost',
  145. data:''
  146. };
  147. },
  148. methods: {
  149. load(tree, treeNode, resolve) {
  150. try{
  151. this.loadNodeMap.set(tree.cName, {tree,treeNode,resolve})
  152. this.$axios.get(this.url+'show_model_child_api',{params:{
  153. name:tree.cName
  154. }}).then((res)=>{
  155. let TrainTaskInfo
  156. let tableData
  157. tableData= res.data
  158. for(let i=0;i<tableData.length;i++){
  159. TrainTaskInfo = JSON.parse(tableData[i].TrainTaskInfo)
  160. tableData[i].EngineName = TrainTaskInfo.EngineName.split('-')[0]
  161. tableData[i].ComputeResource = TrainTaskInfo.ComputeResource
  162. tableData[i].cName=tableData[i].Name
  163. tableData[i].Name=''
  164. tableData[i].VersionCount = ''
  165. tableData[i].Children = true
  166. }
  167. resolve(tableData||[])
  168. })
  169. }
  170. catch(e){
  171. this.loading = false;
  172. }
  173. },
  174. tableHeaderStyle({row,column,rowIndex,columnIndex}){
  175. if(rowIndex===0){
  176. return 'background:#f5f5f6;color:#606266'
  177. }
  178. },
  179. handleSizeChange(val){
  180. this.params.pageSize = val
  181. this.getModelList()
  182. },
  183. handleCurrentChange(val){
  184. this.params.page = val
  185. this.getModelList()
  186. },
  187. showcreateVue(name,version,label){
  188. $('.ui.modal.second')
  189. .modal({
  190. centered: false,
  191. onShow:function(){
  192. $('#model_header').text("创建模型新版本")
  193. $('input[name="Name"]').addClass('model_disabled')
  194. $('input[name="Name"]').attr('readonly','readonly')
  195. $('input[name="Version"]').addClass('model_disabled')
  196. $('.ui.dimmer').css({"background-color":"rgb(136, 136, 136,0.7)"})
  197. $("#job-name").empty()
  198. $('#name').val(name)
  199. $('#label').val(label)
  200. let version_string = versionAdd(version)
  201. $('#version').val(version_string)
  202. loadTrainList()
  203. },
  204. onHide:function(){
  205. document.getElementById("formId").reset();
  206. $('input[name="Name"]').removeClass('model_disabled')
  207. $('input[name="Name"]').removeAttr('readonly')
  208. $('#choice_model').dropdown('clear')
  209. $('#choice_version').dropdown('clear')
  210. $('.ui.dimmer').css({"background-color":""})
  211. $('.ui.error.message').text()
  212. $('.ui.error.message').css('display','none')
  213. }
  214. })
  215. .modal('show')
  216. },
  217. check(){
  218. let jobid = document.getElementById("JobId").value
  219. let versionname = document.getElementById("VersionName").value
  220. let name= document.getElementById("name").value
  221. let version= document.getElementById("version").value
  222. if(jobid==""){
  223. $(".required.ten.wide.field").addClass("error")
  224. return false
  225. }else{
  226. $(".required.ten.wide.field").removeClass("error")
  227. }
  228. if(versionname==""){
  229. $(".required.six.widde.field").addClass("error")
  230. return false
  231. }else{
  232. $(".required.six.widde.field").removeClass("error")
  233. }
  234. if(name==""){
  235. $("#modelname").addClass("error")
  236. return false
  237. }else{
  238. $("#modelname").removeClass("error")
  239. }
  240. if(versionname==""){
  241. $("#verionname").addClass("error")
  242. return false
  243. }else{
  244. $("#verionname").removeClass("error")
  245. }
  246. return true
  247. },
  248. submit(){
  249. let context = this
  250. let flag= this.check()
  251. if(flag){
  252. let cName = $("input[name='Name']").val()
  253. let version = $("input[name='Version']").val()
  254. let data = $("#formId").serialize()
  255. const initModel = $("input[name='initModel']").val()
  256. let url_href = version === '0.0.1' ? context.url_create_newModel : context.url_create_newVersion
  257. $("#mask").css({"display":"block","z-index":"9999"})
  258. $.ajax({
  259. url:url_href,
  260. type:'POST',
  261. data:data,
  262. success:function(res){
  263. // context.loadrefresh1(row)
  264. context.getModelList()
  265. $('.ui.modal.second').modal('hide')
  266. if(initModel==='0'){
  267. location.reload()
  268. }
  269. },
  270. error: function(xhr){
  271. // 隐藏 loading
  272. // 只有请求不正常(状态码不为200)才会执行
  273. $('.ui.error.message').text(xhr.responseText)
  274. $('.ui.error.message').css('display','block')
  275. },
  276. complete:function(xhr){
  277. $("#mask").css({"display":"none","z-index":"1"})
  278. }
  279. })
  280. }else{
  281. return false
  282. }
  283. },
  284. loadrefresh(row){
  285. const store = this.$refs.table.store
  286. if(!this.loadNodeMap.get(row.cName)){
  287. const parent = store.states.data
  288. const index = parent.findIndex(child => child.ID == row.ID)
  289. this.getModelList()
  290. }else{
  291. let {tree,treeNode,resolve} = this.loadNodeMap.get(row.cName)
  292. const keys = Object.keys(store.states.lazyTreeNodeMap);
  293. if(keys.includes(row.ID)){
  294. this.getModelList()
  295. }else{
  296. let parentRow = store.states.data.find(child => child.cName == row.cName);
  297. let childrenIndex = store.states.lazyTreeNodeMap[parentRow.ID].findIndex(child => child.ID == row.ID)
  298. parentRow.VersionCount = parentRow.VersionCount-1
  299. const parent = store.states.lazyTreeNodeMap[parentRow.ID]
  300. if(parent.length===1){
  301. this.getModelList()
  302. }else{
  303. parent.splice(childrenIndex, 1);
  304. }
  305. }
  306. }
  307. },
  308. deleteModel(id,name){
  309. let row={cName:name,ID:id}
  310. let _this = this
  311. let flag=1
  312. $('.ui.basic.modal.first')
  313. .modal({
  314. onDeny: function() {
  315. flag = false
  316. },
  317. onApprove: function() {
  318. _this.$axios.delete(_this.url+'delete_model',{
  319. params:{
  320. ID:id
  321. }}).then((res)=>{
  322. _this.loadrefresh(row)
  323. // _this.getModelList()
  324. })
  325. flag = true
  326. },
  327. onHidden: function() {
  328. if (flag == false) {
  329. $('.alert').html('您已取消操作').removeClass('alert-success').addClass('alert-danger').show().delay(1500).fadeOut();
  330. }else{
  331. $('.alert').html('删除成功').removeClass('alert-danger').addClass('alert-success').show().delay(1500).fadeOut();
  332. }
  333. }
  334. })
  335. .modal('show')
  336. },
  337. getModelList(){
  338. try {
  339. this.$refs.table.store.states.lazyTreeNodeMap = {}
  340. this.$axios.get(location.href+'_api',{
  341. params:this.params
  342. }).then((res)=>{
  343. $(".ui.grid").removeAttr("style")
  344. $("#loadContainer").removeClass("loader")
  345. let TrainTaskInfo
  346. this.tableData = res.data.data
  347. for(let i=0;i<this.tableData.length;i++){
  348. TrainTaskInfo = JSON.parse(this.tableData[i].TrainTaskInfo)
  349. this.tableData[i].cName=this.tableData[i].Name
  350. this.tableData[i].EngineName = TrainTaskInfo.EngineName.split('-')[0]
  351. this.tableData[i].ComputeResource = TrainTaskInfo.ComputeResource
  352. this.tableData[i].hasChildren = res.data.data[i].VersionCount===1 ? false : true
  353. }
  354. this.totalNum = res.data.count
  355. // if(res.data.count===1 && res.data.data[0].VersionCount===1){
  356. // location.reload()
  357. // }
  358. })
  359. }catch (e) {
  360. console.log(e)
  361. }
  362. },
  363. },
  364. computed:{
  365. loadhref(){
  366. return this.url+'downloadall?ID='
  367. },
  368. showinfoHref(){
  369. return this.url + 'show_model_info?name='
  370. },
  371. transTime(){
  372. return function(time){
  373. let date = new Date(time * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  374. let Y = date.getFullYear() + '-';
  375. let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
  376. let D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
  377. let h = (date.getHours() < 10 ? '0'+date.getHours():date.getHours())+ ':';
  378. let m = (date.getMinutes() < 10 ? '0'+date.getMinutes():date.getMinutes()) + ':';
  379. let s = date.getSeconds() < 10 ? '0'+date.getSeconds():date.getSeconds();
  380. return Y+M+D+h+m+s;
  381. }
  382. },
  383. renderSize(){
  384. return function(value){
  385. if(null==value||value==''){
  386. return "0 Bytes";
  387. }
  388. var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB");
  389. var index=0;
  390. var srcsize = parseFloat(value);
  391. index=Math.floor(Math.log(srcsize)/Math.log(1024));
  392. var size =srcsize/Math.pow(1024,index);
  393. size=size.toFixed(2);//保留的小数位数
  394. return size+unitArr[index];
  395. }
  396. }
  397. },
  398. mounted() {
  399. this.submitId = document.getElementById("submitId")
  400. this.getModelList()
  401. this.url = location.href.split('show_model')[0]
  402. this.submitId.addEventListener("click", this.submit)
  403. this.url_create_newVersion = this.url + 'create_model'
  404. this.url_create_newModel = this.url + 'create_new_model'
  405. },
  406. beforeDestroy() { // 实例销毁之前对点击事件进行解绑
  407. this.submitId.removeEventListener('click', this.submit);
  408. }
  409. };
  410. </script>
  411. <style scoped>
  412. /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  413. background-color: #5bb973;
  414. color: #FFF;
  415. }
  416. /deep/ .el-pagination.is-background .el-pager li.active {
  417. color: #fff;
  418. cursor: default;
  419. }
  420. /deep/ .el-pagination.is-background .el-pager li:hover {
  421. color: #5bb973;
  422. }
  423. /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
  424. color: #5bb973;
  425. }
  426. /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
  427. background-color: #5bb973;
  428. color: #FFF;
  429. }
  430. /deep/ .el-pager li.active {
  431. color: #08C0B9;
  432. cursor: default;
  433. }
  434. /deep/ .el-pagination .el-pager li:hover {
  435. color: #08C0B9;
  436. }
  437. /deep/ .el-pagination .el-pager li:not(.disabled):hover {
  438. color: #08C0B9;
  439. }
  440. .text-over{
  441. overflow: hidden;
  442. text-overflow: ellipsis;
  443. vertical-align: middle;
  444. white-space: nowrap;
  445. }
  446. .el-icon-arrow-right{
  447. font-family: element-icons!important;
  448. speak: none;
  449. font-style: normal;
  450. font-weight: 400;
  451. font-feature-settings: normal;
  452. font-variant: normal;
  453. text-transform: none;
  454. line-height: 1;
  455. vertical-align: middle;
  456. display: inline-block;
  457. -webkit-font-smoothing: antialiased;
  458. -moz-osx-font-smoothing: grayscale;
  459. border: 1px solid #D4D4D5;
  460. border-radius: 50%;
  461. color: #D4D4D5;
  462. margin-right: 4px;
  463. }
  464. .el-icon-arrow-right::before{
  465. content: "\e6e0";
  466. }
  467. .expand-icon{
  468. display: inline-block;
  469. width: 20px;
  470. line-height: 20px;
  471. height: 20px;
  472. text-align: center;
  473. margin-right: 3px;
  474. font-size: 12px;
  475. }
  476. /deep/ .el-table_1_column_1.is-left .cell {padding-right: 0px !important;white-space: nowrap;}
  477. /deep/ .el-table__expand-icon .el-icon-arrow-right{
  478. font-family: element-icons!important;
  479. speak: none;
  480. font-style: normal;
  481. font-weight: 400;
  482. font-feature-settings: normal;
  483. font-variant: normal;
  484. text-transform: none;
  485. line-height: 1;
  486. vertical-align: middle;
  487. display: inline-block;
  488. -webkit-font-smoothing: antialiased;
  489. -moz-osx-font-smoothing: grayscale;
  490. border: 1px solid #3291F8;
  491. border-radius: 50%;
  492. color: #3291F8;
  493. margin-right: 4px;
  494. }
  495. .space-around{
  496. display: flex;
  497. justify-content: space-around;
  498. }
  499. .disabled {
  500. cursor: default;
  501. pointer-events: none;
  502. color: rgba(0,0,0,.6) !important;
  503. opacity: .45 !important;
  504. }
  505. </style>