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.

modelmanage-local-create-1.vue 14 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <template>
  2. <div>
  3. <div class="header">
  4. <span class="title">{{ type == '1' ? $t('modelManage.modifyModelInfo') : $t('modelManage.importLocalModel')
  5. }}</span>
  6. </div>
  7. <div class="content">
  8. <div class="guide-c" v-if="type != '1'">
  9. <div class="step focused">
  10. <div class="num">1</div>
  11. <div class="txt">{{ $t('modelManage.createModel') }}</div>
  12. </div>
  13. <div class="line"></div>
  14. <div class="step">
  15. <div class="num">2</div>
  16. <div class="txt">{{ $t('modelManage.uploadModelFiles') }}</div>
  17. </div>
  18. </div>
  19. <div class="row-c" v-loading="loading">
  20. <div class="row">
  21. <div class="r-title"><label class="required">{{ $t('modelManage.useCluster') }}</label></div>
  22. <div class="r-content" style="display:flex;">
  23. <div class="cluster-type-btn" v-if="type != 1 || type == 1 && state.type === 0"
  24. :class="state.type === 0 ? 'focused' : ''"
  25. :style="type != 1 ? 'border-top-right-radius:unset;border-bottom-right-radius:unset;' : ''"
  26. @click="state.type = 0; state.engine = '0'">
  27. <svg xmlns="http://www.w3.org/2000/svg"
  28. class="icon styles__StyledSVGIconPathComponent-sc-16fsqc8-0 cSaWDI svg-icon-path-icon fill"
  29. viewBox="0 0 32 32" width="16" height="16">
  30. <defs data-reactroot=""></defs>
  31. <g>
  32. <path
  33. d="M4 3.989c0-0.731 0.593-1.323 1.324-1.323h21.352c0.729 0.005 1.318 0.594 1.324 1.322v24.022c-0.001 0.731-0.593 1.323-1.324 1.323h-21.352c-0.729-0.005-1.318-0.594-1.324-1.322v-24.022zM25.333 14.667v-9.333h-18.667v9.333h18.667zM25.333 17.333h-18.667v9.333h18.667v-9.333zM12 8h8v2.667h-8v-2.667zM12 20h8v2.667h-8v-2.667z">
  34. </path>
  35. </g>
  36. </svg>
  37. <span class="txt">CPU / GPU</span>
  38. </div>
  39. <div class="cluster-type-btn" v-if="type != 1 || type == 1 && state.type === 1"
  40. :class="state.type === 1 ? 'focused' : ''"
  41. :style="type != 1 ? 'border-top-left-radius:unset;border-bottom-left-radius:unset;' : ''"
  42. @click="state.type = 1; state.engine = '2'">
  43. <svg xmlns="http://www.w3.org/2000/svg"
  44. class="icon styles__StyledSVGIconPathComponent-sc-16fsqc8-0 iKfgJk svg-icon-path-icon fill"
  45. viewBox="0 0 32 32" width="16" height="16">
  46. <defs data-reactroot=""></defs>
  47. <g>
  48. <path
  49. d="M4 3.989c0-0.731 0.593-1.323 1.324-1.323h21.352c0.729 0.005 1.318 0.594 1.324 1.322v24.022c-0.001 0.731-0.593 1.323-1.324 1.323h-21.352c-0.729-0.005-1.318-0.594-1.324-1.322v-24.022zM25.333 14.667v-9.333h-18.667v9.333h18.667zM25.333 17.333h-18.667v9.333h18.667v-9.333zM12 8h8v2.667h-8v-2.667zM12 20h8v2.667h-8v-2.667z">
  50. </path>
  51. </g>
  52. </svg>
  53. <span class="txt">Ascend NPU</span>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="row" :class="nameErr ? 'error' : ''">
  58. <div class="r-title"><label class="required">{{ $t('modelManage.modelName') }}</label></div>
  59. <div class="r-content">
  60. <el-input size="medium" :maxLength="25" v-model="state.name" @blur="checkName"
  61. :placeholder="$t('modelManage.pleaseInputModelName')">
  62. </el-input>
  63. </div>
  64. </div>
  65. <div class="row" v-show="isShowVersion">
  66. <div class="r-title"><label class="required">{{ $t('modelManage.version') }}</label></div>
  67. <div class="r-content">
  68. <el-input class="input-disabled" style="width:288px;" size="medium" v-model="state.version" readonly>
  69. </el-input>
  70. </div>
  71. </div>
  72. <div class="row">
  73. <div class="r-title"><label class="required">{{ $t('modelManage.modelEngine') }}</label></div>
  74. <div class="r-content">
  75. <el-select style="width:288px;" size="medium" v-model="state.engine" placeholder="">
  76. <el-option v-for="item in engineList" :key="item.k" :label="item.v" :value="item.k">
  77. </el-option>
  78. </el-select>
  79. </div>
  80. </div>
  81. <div class="row">
  82. <div class="r-title"><label>{{ $t('modelManage.modelLabel') }}</label></div>
  83. <div class="r-content">
  84. <el-input size="medium" :maxLength="255" v-model="state.label"
  85. :placeholder="$t('modelManage.modelLabelInputTips')" @input="labelInput"></el-input>
  86. </div>
  87. </div>
  88. <div class="row" style="align-items:flex-start;">
  89. <div class="r-title"><label>{{ $t('modelManage.modelDescr') }}</label></div>
  90. <div class="r-content">
  91. <el-input type="textarea" :maxLength="255" size="medium" v-model="state.description" :rows="3"
  92. :placeholder="$t('modelManage.modelDescrInputTips')">
  93. </el-input>
  94. </div>
  95. </div>
  96. <div class="row" style="margin-top:20px">
  97. <div class="r-title"><label></label></div>
  98. <div class="r-content">
  99. <el-button size="medium" class="green" @click="submit">{{ type == '1' ? $t('modelManage.confirm') :
  100. $t('modelManage.createModel')
  101. }}
  102. </el-button>
  103. <el-button size="medium" @click="cancel">{{ $t('modelManage.cancel') }}</el-button>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. <script>
  111. import { saveLocalModel, getModelInfoByName, modifyModel } from '~/apis/modules/modelmanage';
  112. import { getUrlSearchParams } from '~/utils';
  113. import { MODEL_ENGINES } from '~/const'
  114. const REPO_NAME = location.pathname.split('/')[2];
  115. const MAX_LABEL_COUNT = 5;
  116. export default {
  117. data() {
  118. return {
  119. type: '0', // 1-修改,其它-新增
  120. loading: false,
  121. state: {
  122. type: 0,
  123. name: REPO_NAME + '_model_' + Math.random().toString(36).substr(2, 4),
  124. version: '0.0.1',
  125. engine: '0',
  126. label: '',
  127. description: '',
  128. },
  129. nameErr: false,
  130. isShowVersion: false,
  131. engineList: MODEL_ENGINES,
  132. };
  133. },
  134. components: {},
  135. methods: {
  136. checkName() {
  137. this.nameErr = !this.state.name;
  138. return !this.nameErr;
  139. },
  140. labelInput() {
  141. const hasEndSpace = this.state.label[this.state.label.length - 1] == ' ';
  142. const list = this.state.label.trim().split(' ').filter(label => label != '');
  143. this.state.label = list.slice(0, MAX_LABEL_COUNT).join(' ') + (hasEndSpace && list.length < MAX_LABEL_COUNT ? ' ' : '');
  144. },
  145. submit() {
  146. if (!this.checkName()) {
  147. // this.$message({
  148. // type: 'info',
  149. // message: this.$t('modelManage.pleaseInputModelName'),
  150. // });
  151. return;
  152. }
  153. const submintApi = this.type == '1' ? modifyModel : saveLocalModel;
  154. submintApi({
  155. repo: location.pathname.split('/').slice(0, 3).join('/'),
  156. ...this.state,
  157. }).then(res => {
  158. res = res.data;
  159. if (res && res.code == '0') {
  160. if (this.type == '1') {
  161. this.goDetail();
  162. return;
  163. }
  164. const list = window.location.href.split('/');
  165. list.pop();
  166. list.push('create_local_model_2');
  167. window.location.href = list.join('/') + '?type=0&name=' + encodeURIComponent(this.state.name) + '&id=' + res.id;
  168. } else if (res && res.code == '-1') {
  169. this.$message({
  170. type: 'error',
  171. message: res.msg,
  172. });
  173. } else {
  174. this.$message({
  175. type: 'error',
  176. message: this.type == '1' ? this.$t('modelManage.modelModifyFailed') : this.$t('modelManage.modelCreateFailed'),
  177. });
  178. }
  179. }).catch(err => {
  180. console.log(err);
  181. });
  182. },
  183. cancel() {
  184. const list = window.location.href.split('/');
  185. list.pop();
  186. list.push('show_model');
  187. window.location.href = list.join('/');
  188. },
  189. goDetail() {
  190. const list = window.location.href.split('/');
  191. list.pop();
  192. list.push('show_model_info');
  193. window.location.href = list.join('/') + '?name=' + encodeURIComponent(this.state.name);
  194. }
  195. },
  196. mounted() {
  197. const urlParams = getUrlSearchParams();
  198. if (urlParams.type == '1' && urlParams.name && urlParams.id) { // update
  199. this.type = urlParams.type;
  200. this.state.name = urlParams.name;
  201. this.state.id = urlParams.id;
  202. this.loading = true;
  203. getModelInfoByName({
  204. repo: location.pathname.split('/').slice(0, 3).join('/'),
  205. name: urlParams.name,
  206. id: urlParams.id
  207. }).then(res => {
  208. this.loading = false;
  209. const list = res.data;
  210. if (list && list.length) {
  211. const data = list[0];
  212. this.state.type = data.type;
  213. this.state.id = data.id;
  214. this.state.name = data.name;
  215. this.state.version = data.version;
  216. this.state.engine = data.engine.toString();
  217. this.state.label = data.label;
  218. this.state.description = data.description;
  219. }
  220. }).catch(err => {
  221. this.loading = false;
  222. console.log(err);
  223. this.cancel();
  224. });
  225. }
  226. },
  227. beforeDestroy() {
  228. },
  229. };
  230. </script>
  231. <style scoped lang="less">
  232. .header {
  233. height: 45px;
  234. border-color: rgb(212, 212, 213);
  235. border-width: 1px;
  236. border-style: solid;
  237. border-radius: 5px 5px 0px 0px;
  238. font-size: 14px;
  239. background: rgb(240, 240, 240);
  240. display: flex;
  241. align-items: center;
  242. .title {
  243. font-weight: 600;
  244. font-size: 16px;
  245. color: rgb(16, 16, 16);
  246. margin-left: 10px;
  247. }
  248. }
  249. .content {
  250. margin-top: -1px;
  251. border-color: rgb(212, 212, 213);
  252. border-width: 1px;
  253. border-style: solid;
  254. padding: 30px 0;
  255. border-top: none;
  256. .guide-c {
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. margin-bottom: 20px;
  261. .step {
  262. display: flex;
  263. align-items: center;
  264. color: rgb(136, 136, 136);
  265. .num {
  266. border: 1px solid rgb(136, 136, 136);
  267. width: 34px;
  268. height: 34px;
  269. font-size: 24px;
  270. text-align: center;
  271. line-height: 34px;
  272. border-radius: 17px;
  273. margin-right: 8px;
  274. }
  275. .txt {
  276. font-weight: 600;
  277. }
  278. &.focused {
  279. color: rgb(22, 132, 252);
  280. .num {
  281. border-color: rgb(22, 132, 252);
  282. }
  283. }
  284. }
  285. .line {
  286. height: 2px;
  287. width: 50px;
  288. background-color: rgb(187, 187, 187);
  289. margin: 0 10px;
  290. }
  291. }
  292. .row-c {
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. flex-direction: column;
  297. margin: 0 auto;
  298. width: 80%;
  299. .row {
  300. width: 100%;
  301. display: flex;
  302. align-items: center;
  303. margin: 8px 0;
  304. margin-left: -190px;
  305. .r-title {
  306. text-align: right;
  307. font-size: .92857143em;
  308. font-weight: 700;
  309. color: rgba(0, 0, 0, .87);
  310. width: 200px;
  311. margin-right: 28px;
  312. position: relative;
  313. .required {
  314. &::after {
  315. position: absolute;
  316. margin: -0.2em 0 0 0.2em;
  317. content: '*';
  318. color: #db2828;
  319. }
  320. }
  321. }
  322. &.error {
  323. .r-title {
  324. color: #9f3a38;
  325. }
  326. .r-content {
  327. /deep/.el-input__inner {
  328. color: #9f3a38;
  329. background: #fff6f6;
  330. border-color: #e0b4b4;
  331. &::placeholder {
  332. color: #e0b4b4;
  333. }
  334. }
  335. }
  336. }
  337. .r-content {
  338. flex: 1;
  339. .cluster-type-btn {
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. border: 1px solid #DCDFE6;
  344. height: 36px;
  345. padding: 10px;
  346. cursor: pointer;
  347. border-radius: 4px;
  348. .icon {
  349. margin-right: 5px;
  350. }
  351. &.focused {
  352. border-color: rgb(50, 145, 248);
  353. color: rgb(50, 145, 248);
  354. cursor: default;
  355. .icon {
  356. :not([stroke]) {
  357. fill: rgb(50, 145, 248);
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. .input-disabled {
  367. /deep/ .el-input__inner {
  368. background-color: #f5f5f6 !important;
  369. color: #888888 !important;
  370. }
  371. }
  372. .el-select-dropdown__item.selected {
  373. color: rgba(0, 0, 0, .95);
  374. }
  375. /deep/ .el-button {
  376. background-color: #e0e1e2;
  377. color: rgba(0, 0, 0, .6);
  378. border-color: transparent;
  379. transition: opacity .1s ease, background-color .1s ease, color .1s ease, box-shadow .1s ease, background .1s ease, -webkit-box-shadow .1s ease;
  380. will-change: auto;
  381. -webkit-tap-highlight-color: transparent;
  382. &:hover {
  383. border-color: transparent;
  384. background-color: #cacbcd;
  385. color: rgba(0, 0, 0, .8);
  386. }
  387. &:focus {
  388. background-color: #cacbcd;
  389. color: rgba(0, 0, 0, .8);
  390. border-color: transparent;
  391. }
  392. &:active {
  393. background-color: #babbbc;
  394. color: rgba(0, 0, 0, .9);
  395. border-color: transparent;
  396. }
  397. &.green {
  398. background-color: #5bb973;
  399. color: #fff;
  400. &:hover {
  401. background-color: #16ab39;
  402. border-color: transparent;
  403. }
  404. &:focus {
  405. background-color: #0ea432;
  406. border-color: transparent;
  407. }
  408. &:active {
  409. background-color: #198f35;
  410. border-color: transparent;
  411. }
  412. }
  413. }
  414. /deep/ .el-select {
  415. .is-focus {
  416. .el-input__inner {
  417. border-color: #85b7d9;
  418. }
  419. }
  420. }
  421. /deep/ .el-input__inner {
  422. &:focus {
  423. border-color: #85b7d9;
  424. }
  425. }
  426. /deep/ .el-textarea__inner {
  427. &:focus {
  428. border-color: #85b7d9;
  429. }
  430. }
  431. </style>