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.

index.vue 18 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="新建Notebook调试任务"
  5. :visible.sync="dialogVisible"
  6. width="50%"
  7. :close-on-click-modal="false"
  8. @closed="handleClose"
  9. >
  10. <div class="wrapper">
  11. <div v-show="alertCb" class="ui message alert-info">
  12. <div style="display: flex;align-items: center;">
  13. <i class="ri-information-line" style="font-size: 35px;color: rgba(242, 113, 28, 1);;"></i>
  14. <div style="text-align: left;margin-left: 1rem;">
  15. <div style="font-weight: 600;line-height: 2;">您已经有 <span style="color:rgba(242, 113, 28, 1);">同类任务</span> 正在等待或运行中,请等待任务结束再创建</div>
  16. <div style="color:#939393">可以在 “<a href="/cloudbrains" target="_blank">个人中心 &gt; 云脑任务</a>” 查看您所有的云脑任务。</div>
  17. </div>
  18. </div>
  19. </div>
  20. <div
  21. class="three-resource-type"
  22. :class="{ active: selectIndex == 0 }"
  23. @click="selectResource(0,'waitCountGpu')"
  24. >
  25. <div class="resource-child-node">
  26. <div class="resource-type-icon background-C">
  27. <span class="text">C</span>
  28. </div>
  29. <div class="resource-type-detail">
  30. <div class="detail-title"><span>CPU 环境</span></div>
  31. <div class="detail-spec">
  32. <span>{{cpuSpec}}</span>
  33. </div>
  34. <div class="detail-spec">
  35. <span>镜像:{{notebookInfo.imageCpuDescription}}</span>
  36. </div>
  37. </div>
  38. <div class="resource-select">
  39. <i v-if="selectIndex===0" :class="{'slide-in-bottom': !slideActive && !initSelect }" class="ri-checkbox-circle-line green"></i>
  40. <i
  41. class="ri-checkbox-blank-circle-line gray"
  42. :class="{'fade-out':selectIndex===0}"
  43. ></i>
  44. </div>
  45. </div>
  46. </div>
  47. <div
  48. class="three-resource-type"
  49. :class="{ active: selectIndex == 1 }"
  50. @click="selectResource(1,'waitCountGpu')"
  51. >
  52. <div class="resource-child-node">
  53. <div class="resource-type-icon background-G">
  54. <span class="text">G</span>
  55. </div>
  56. <div class="resource-type-detail">
  57. <div class="detail-title"><span>GPU 环境</span></div>
  58. <div class="detail-spec">
  59. <span>{{gpuSpec}}</span>
  60. </div>
  61. <div class="detail-spec">
  62. <span>镜像:{{notebookInfo.imageGpuDescription}}</span>
  63. </div>
  64. </div>
  65. <div class="resource-select">
  66. <i v-if="selectIndex===1 && !initSelect" :class="[slideActive && !initSelect ?'slide-in-top':'slide-in-bottom']" class="ri-checkbox-circle-line green"></i>
  67. <i v-if="selectIndex===1 && initSelect" class="ri-checkbox-circle-line green"></i>
  68. <i
  69. class="ri-checkbox-blank-circle-line gray"
  70. :class="{'fade-out':selectIndex===1}"
  71. ></i>
  72. </div>
  73. </div>
  74. </div>
  75. <div
  76. class="three-resource-type"
  77. :class="{ active: selectIndex == 2 }"
  78. @click="selectResource(2,'waitCountNpu')"
  79. >
  80. <div class="resource-child-node">
  81. <div class="resource-type-icon background-N">
  82. <span class="text">N</span>
  83. </div>
  84. <div class="resource-type-detail">
  85. <div class="detail-title"><span>NPU 环境</span></div>
  86. <div class="detail-spec">
  87. <span>{{npuSpec}}</span>
  88. </div>
  89. <div class="detail-spec">
  90. <span>镜像:{{notebookInfo.imageCpuDescription}}</span>
  91. </div>
  92. </div>
  93. <div class="resource-select">
  94. <i v-if="selectIndex===2" :class="{'slide-in-top': slideActive && !initSelect}" class="ri-checkbox-circle-line green"></i>
  95. <i
  96. class="ri-checkbox-blank-circle-line gray"
  97. :class="{'fade-out':selectIndex===2}"
  98. ></i>
  99. </div>
  100. </div>
  101. </div>
  102. <div class="resource-footer">
  103. <div class="resource-operate" v-if="selectIndex==0">
  104. <button v-if="btnStatus[0]===0" class="ui green small button" @click="createTask(0)"></i>新建任务1</button>
  105. <button v-else-if="btnStatus[0]===1"class="ui disabled small button" style="background-color: #888;"><i class="loading spinner icon" style="color: #fff;"></i>新建任务</button>
  106. <button v-else>aaaa</button>
  107. <span>当前有个<span style="color: red;">{{waitCount}}</span>任务在排队</span>
  108. </div>
  109. <div class="resource-operate" v-if="selectIndex==1">
  110. <button v-if="btnStatus[1]===0" class="ui green small button" @click="createTask(1)"></i>新建任务2</button>
  111. <button v-else-if="btnStatus[1]===1"class="ui disabled small button" style="background-color: #888;"><i class="loading spinner icon" style="color: #fff;"></i>新建任务</button>
  112. <button v-else>aaaa</button>
  113. <span>当前有个<span style="color: red;">{{waitCount}}</span>任务在排队</span>
  114. </div>
  115. <div class="resource-operate" v-if="selectIndex==2">
  116. <button v-if="btnStatus[2]===0" class="ui green small button" @click="createTask(2)"></i>新建任务3</button>
  117. <button v-else-if="btnStatus[2]===1"class="ui disabled small button" style="background-color: #888;"><i class="loading spinner icon" style="color: #fff;"></i>新建任务</button>
  118. <div v-else>
  119. <button class="ui small button" style="background-color: #1684fc;color:#fff">
  120. <a :href="deubgUrlNpu" target="_blank">调试</a>
  121. </button>
  122. <button class="ui small button" @click="stopDebug(2)">停止</button>
  123. </div>
  124. <span>当前有个<span style="color: red;">{{waitCount}}</span>任务在排队</span>
  125. </div>
  126. </div>
  127. </div>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. import { getFileNotebook,createNotebook,getCb1Notebook,getCb2Notebook,stopNotebook } from "~/apis/modules/notobook";
  133. import { Message } from "element-ui";
  134. let timerCb1,timerCb2
  135. let {AppSubUrl} = window.config
  136. export default {
  137. data() {
  138. return {
  139. dialogVisible: false,
  140. selectIndex: 0,
  141. slideActive:true,
  142. initSelect:true,
  143. notebookInfo:{specCpu:{acc_cards_num:0},specGpu:{acc_cards_num:0},specNpu:{acc_cards_num:0}},
  144. waitCount:0,
  145. fileInfo:{
  146. file:'',
  147. branch_name:'',
  148. owner_name:'',
  149. project_name:'',
  150. },
  151. btnStatus:{0:0,1:0,2:0},
  152. firtstStatus:0,
  153. secondStatus:0,
  154. thirdStatus:0,
  155. alertCb:false,
  156. deubgUrlNpu:'',
  157. deubgUrlGpu:'',
  158. deubgUrlNpuStop:'',
  159. deubgUrlGpuStop:'',
  160. };
  161. },
  162. methods: {
  163. handleClose(done) {
  164. console.log("close")
  165. this.initSelect = true
  166. },
  167. selectResource(index,type) {
  168. this.getNotebookInfo()
  169. if(index==this.selectIndex){
  170. return
  171. }
  172. if(index>this.selectIndex){
  173. this.slideActive = true
  174. }else{
  175. this.slideActive = false
  176. }
  177. this.selectIndex = index;
  178. this.initSelect = false
  179. this.waitCount += this.notebookInfo[type] +1
  180. this.alertCb = false
  181. },
  182. getNotebookInfo(){
  183. getFileNotebook().then((res)=>{
  184. console.log(res)
  185. if(res.data.code==0){
  186. this.notebookInfo = res.data
  187. this.waitCount = res.data.waitCountGpu
  188. }else{
  189. console.log(res.data.message)
  190. Message.error(res.data.message)
  191. }
  192. }).catch((err)=>{
  193. Message.error(err)
  194. console.log(err)
  195. })
  196. },
  197. getCb1NotebookInfo(path,id){
  198. getCb1Notebook(path,id).then((res)=>{
  199. console.log(res)
  200. if(res.status===200){
  201. if(res.data.JobStatus==="RUNNING"){
  202. this.btnStatus[2]=2
  203. this.deubgUrlGpu = `${AppSubUrl}/${this.fileInfo.owner_name}/${this.notebookInfo.projectName}/cloudbrain/${id}/debug`
  204. this.deubgUrlGpuStop = `${AppSubUrl}/${this.fileInfo.owner_name}/${this.notebookInfo.projectName}/cloudbrain/${id}/stop`
  205. clearInterval(timerCb1)
  206. }
  207. }
  208. })
  209. },
  210. getCb2NotebookInfo(path,id){
  211. getCb2Notebook(path,id).then((res)=>{
  212. console.log(res)
  213. if(res.status===200){
  214. if(res.data.JobStatus==="RUNNING"){
  215. this.btnStatus[2]=2
  216. this.deubgUrlNpu = `${AppSubUrl}/${this.fileInfo.owner_name}/${this.notebookInfo.projectName}/modelarts/notebook/${id}/debug`
  217. this.deubgUrlNpuStop = `${AppSubUrl}/${this.fileInfo.owner_name}/${this.notebookInfo.projectName}/modelarts/notebook/${id}/stop`
  218. clearInterval(timerCb2)
  219. }
  220. }
  221. })
  222. },
  223. stopDebug(index){
  224. if(index===2){
  225. stopNotebook(this.deubgUrlNpuStop).then((res)=>{
  226. console.log(res)
  227. })
  228. }else{
  229. stopNotebook(this.deubgUrlGpuStop).then((res)=>{
  230. console.log(res)
  231. })
  232. }
  233. },
  234. createTask(index){
  235. this.btnStatus[index]=1
  236. const data = {type:index,...this.fileInfo}
  237. let repoPath = `repos/${this.fileInfo.owner_name}/${this.fileInfo.project_name}`
  238. createNotebook(data).then((res)=>{
  239. console.log("=========",res)
  240. if(res.data.code===0 && res.status===200){
  241. // this.btnStatus[index]=2
  242. if(index===2){
  243. console.log("index",index)
  244. timerCb2 = setInterval(() => {
  245. setTimeout(this.getCb2NotebookInfo(repoPath,res.data.message), 0)
  246. }, 10000)
  247. }else{
  248. timerCb1 = setInterval(() => {
  249. setTimeout(this.getCb1NotebookInfo(repoPath,res.data.message), 0)
  250. }, 10000)
  251. }
  252. this.alertCb = false
  253. }else if(res.data.code===1 && res.status===403){
  254. this.btnStatus[index]=0
  255. }else{
  256. this.btnStatus[index]=0
  257. Message.error(res.data.message)
  258. this.alertCb = true
  259. }
  260. }).catch((err)=>{
  261. this.btnStatus[index]=0
  262. this.alertCb = false
  263. Message.error(err)
  264. })
  265. }
  266. },
  267. computed: {
  268. cpuSpec(){
  269. return `规格:GPU: ${this.notebookInfo.specCpu.acc_cards_num}*${this.notebookInfo.specCpu.acc_card_type},
  270. CPU: ${this.notebookInfo.specCpu.cpu_cores}, 显存: ${this.notebookInfo.specCpu.gpu_mem_gi_b}GB,
  271. 内存: ${this.notebookInfo.specCpu.mem_gi_b}GB, 共享内存: ${this.notebookInfo.specCpu.share_mem_gi_b}GB`
  272. },
  273. npuSpec(){
  274. return `规格:NPU: ${this.notebookInfo.specNpu.acc_cards_num}*${this.notebookInfo.specNpu.acc_card_type},
  275. CPU: ${this.notebookInfo.specNpu.cpu_cores}, 显存: ${this.notebookInfo.specNpu.gpu_mem_gi_b}GB,
  276. 内存: ${this.notebookInfo.specNpu.mem_gi_b}GB, 共享内存: ${this.notebookInfo.specNpu.share_mem_gi_b}GB`
  277. },
  278. gpuSpec(){
  279. return `规格:NPU: ${this.notebookInfo.specGpu.acc_cards_num}*${this.notebookInfo.specGpu.acc_card_type},
  280. CPU: ${this.notebookInfo.specGpu.cpu_cores}, 显存: ${this.notebookInfo.specGpu.gpu_mem_gi_b}GB,
  281. 内存: ${this.notebookInfo.specGpu.mem_gi_b}GB, 共享内存: ${this.notebookInfo.specGpu.share_mem_gi_b}GB`
  282. }
  283. },
  284. beforeDestroy() {
  285. clearInterval(timerCb1)
  286. clearInterval(timerCb2)
  287. },
  288. mounted() {
  289. this.getNotebookInfo()
  290. // this.dialogVisible = true
  291. console.log("-----------aaaaa--");
  292. const selfData = document.querySelector('#__vue-self-data')
  293. this.fileInfo.file = selfData.getAttribute('data-file')
  294. this.fileInfo.branch_name = selfData.getAttribute('data-branch')
  295. this.fileInfo.owner_name = selfData.getAttribute('data-owner')
  296. this.fileInfo.project_name = selfData.getAttribute('data-project')
  297. console.log(this.fileInfo)
  298. let that = this;
  299. document
  300. .querySelector("#notebook-debug")
  301. .addEventListener("click", function () {
  302. that.dialogVisible = true;
  303. });
  304. },
  305. };
  306. </script>
  307. <style scoped lang="less">
  308. /deep/ .el-dialog__header {
  309. text-align: left;
  310. height: 45px;
  311. background: rgb(240, 240, 240);
  312. border-radius: 5px 5px 0px 0px;
  313. border-bottom: 1px solid rgb(212, 212, 213);
  314. padding: 0 15px;
  315. display: flex;
  316. align-items: center;
  317. font-weight: 500;
  318. font-size: 16px;
  319. color: rgb(16, 16, 16);
  320. font-family: Roboto;
  321. .el-dialog__title {
  322. font-weight: 600;
  323. font-size: 15px;
  324. color: rgb(16, 16, 16);
  325. }
  326. .el-dialog__headerbtn {
  327. top: 15px;
  328. right: 15px;
  329. }
  330. }
  331. /deep/ .el-dialog__body {
  332. padding: 55px 15px 0 15px;
  333. }
  334. .wrapper {
  335. width: 100%;
  336. .active {
  337. background: linear-gradient(
  338. 269.2deg,
  339. rgba(183, 247, 255, 0.5) 0%,
  340. rgba(233, 233, 255, 0) 78.67%
  341. );
  342. border-radius: 5px 5px 0px 0px;
  343. }
  344. .alert-info{
  345. width: 70%;
  346. background-color: rgba(242, 113, 28, 0.05);
  347. border: 1px solid rgb(242, 113, 28);
  348. border-radius: 5px;
  349. margin: 0 auto;
  350. padding-bottom: 10px;
  351. }
  352. .three-resource-type {
  353. width: 70%;
  354. margin: 0 auto;
  355. display: flex;
  356. border-top: 1px solid rgba(16, 16, 16, 0.1);
  357. cursor: pointer;
  358. &:first-child {
  359. border: none;
  360. }
  361. .resource-child-node {
  362. display: flex;
  363. align-items: center;
  364. width: 100%;
  365. height: 115px;
  366. .resource-type-icon {
  367. width: 50px;
  368. height: 50px;
  369. line-height: 20px;
  370. border-radius: 25px;
  371. text-align: center;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. .text {
  376. font-size: 26px;
  377. color: rgba(251, 251, 251, 1);
  378. font-family: ZKXiaoWeiLogo-regular;
  379. }
  380. }
  381. .background-C {
  382. background: linear-gradient(
  383. 134.2deg,
  384. rgba(130, 209, 246, 1) 0%,
  385. rgba(41, 182, 244, 1) 51.94%,
  386. rgba(0, 137, 205, 1) 102.83%
  387. );
  388. }
  389. .background-N {
  390. background: linear-gradient(
  391. 151.47deg,
  392. rgba(123, 50, 178, 1) 20.02%,
  393. rgba(64, 26, 93, 1) 100%
  394. );
  395. }
  396. .background-G {
  397. background: linear-gradient(
  398. -25.25deg,
  399. rgba(254, 86, 77, 1) 9.3%,
  400. rgba(251, 155, 54, 1) 38.86%,
  401. rgba(249, 202, 38, 1) 67.95%
  402. );
  403. }
  404. }
  405. .resource-type-detail {
  406. margin-left: 23px;
  407. .detail-title {
  408. font-family: SourceHanSansSC;
  409. font-weight: 500;
  410. font-size: 16px;
  411. color: rgb(16, 16, 16);
  412. font-style: normal;
  413. letter-spacing: 0px;
  414. line-height: 32px;
  415. text-decoration: none;
  416. }
  417. .detail-spec {
  418. font-family: SourceHanSansSC;
  419. font-weight: 400;
  420. font-size: 14px;
  421. color: rgba(136, 136, 136, 1);
  422. font-style: normal;
  423. letter-spacing: 0px;
  424. line-height: 24px;
  425. text-decoration: none;
  426. }
  427. }
  428. .resource-select {
  429. margin-left: auto;
  430. margin-right: 20px;
  431. font-size: 20px;
  432. height: 100%;
  433. display: flex;
  434. align-items: center;
  435. .green {
  436. color: green;
  437. }
  438. .gray {
  439. color: rgba(16, 16, 16, 0.1);
  440. }
  441. }
  442. }
  443. .resource-footer {
  444. margin-top: 40px;
  445. border-top: 1px solid rgba(16, 16, 16, 0.1);
  446. height: 71px;
  447. display: flex;
  448. align-items: center;
  449. .resource-operate {
  450. display: flex;
  451. align-items: center;
  452. }
  453. }
  454. .slide-in-top {
  455. -webkit-animation: slide-in-top 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  456. animation: slide-in-top 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  457. }
  458. .slide-in-bottom {
  459. -webkit-animation: slide-in-bottom 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  460. animation: slide-in-bottom 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  461. }
  462. .fade-out {
  463. -webkit-animation: fade-in 1.2s cubic-bezier(0.39, 0.575, 0.565, 1) both;
  464. animation: fade-in 1.2s cubic-bezier(0.39, 0.575, 0.565, 1) both;
  465. position: absolute
  466. }
  467. @-webkit-keyframes slide-in-top {
  468. 0% {
  469. -webkit-transform: translateY(-50px);
  470. transform: translateY(-50px);
  471. opacity: 0;
  472. }
  473. 100% {
  474. -webkit-transform: translateY(0);
  475. transform: translateY(0);
  476. opacity: 1;
  477. }
  478. }
  479. @keyframes slide-in-top {
  480. 0% {
  481. -webkit-transform: translateY(-50px);
  482. transform: translateY(-50px);
  483. opacity: 0;
  484. }
  485. 100% {
  486. -webkit-transform: translateY(0);
  487. transform: translateY(0);
  488. opacity: 1;
  489. }
  490. }
  491. @-webkit-keyframes slide-in-bottom {
  492. 0% {
  493. -webkit-transform: translateY(50px);
  494. transform: translateY(50px);
  495. opacity: 0;
  496. }
  497. 100% {
  498. -webkit-transform: translateY(0);
  499. transform: translateY(0);
  500. opacity: 1;
  501. }
  502. }
  503. @keyframes slide-in-bottom {
  504. 0% {
  505. -webkit-transform: translateY(50px);
  506. transform: translateY(50px);
  507. opacity: 0;
  508. }
  509. 100% {
  510. -webkit-transform: translateY(0);
  511. transform: translateY(0);
  512. opacity: 1;
  513. }
  514. }
  515. @-webkit-keyframes fade-in {
  516. 0% {
  517. opacity: 1;
  518. }
  519. 100% {
  520. opacity: 0;
  521. }
  522. }
  523. @keyframes fade-in {
  524. 0% {
  525. opacity: 1;
  526. }
  527. 100% {
  528. opacity: 0;
  529. }
  530. }
  531. }
  532. </style>