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