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

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