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

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