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