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 23 kB

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