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

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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">
  89. <div class="r-title"><label>模型权限</label></div>
  90. <div class="r-content">
  91. <el-radio-group v-model="state.isPrivate" >
  92. <el-radio-button label="true">公开</el-radio-button>
  93. <el-radio-button label="false">私有</el-radio-button>
  94. </el-radio-group>
  95. </div>
  96. </div>
  97. <div class="row" style="align-items:flex-start;">
  98. <div class="r-title"><label>{{ $t('modelManage.modelDescr') }}</label></div>
  99. <div class="r-content">
  100. <el-input type="textarea" :maxLength="255" size="medium" v-model="state.description" :rows="3"
  101. :placeholder="$t('modelManage.modelDescrInputTips')">
  102. </el-input>
  103. </div>
  104. </div>
  105. <div class="row" style="margin-top:20px">
  106. <div class="r-title"><label></label></div>
  107. <div class="r-content">
  108. <el-button size="medium" class="green" @click="submit">{{ type == '1' ? $t('modelManage.confirm') :
  109. $t('modelManage.createModel')
  110. }}
  111. </el-button>
  112. <el-button size="medium" @click="cancel">{{ $t('modelManage.cancel') }}</el-button>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </template>
  119. <script>
  120. import { saveLocalModel, getModelInfoByName, modifyModel } from '~/apis/modules/modelmanage';
  121. import { getUrlSearchParams } from '~/utils';
  122. import { MODEL_ENGINES } from '~/const'
  123. const REPO_NAME = location.pathname.split('/')[2];
  124. const MAX_LABEL_COUNT = 5;
  125. export default {
  126. data() {
  127. return {
  128. type: '0', // 1-修改,其它-新增
  129. loading: false,
  130. state: {
  131. type: 0,
  132. name: REPO_NAME + '_model_' + Math.random().toString(36).substr(2, 4),
  133. version: '0.0.1',
  134. engine: '0',
  135. label: '',
  136. description: '',
  137. },
  138. nameErr: false,
  139. isShowVersion: false,
  140. engineList: MODEL_ENGINES,
  141. };
  142. },
  143. components: {},
  144. methods: {
  145. checkName() {
  146. this.nameErr = !this.state.name;
  147. return !this.nameErr;
  148. },
  149. labelInput() {
  150. const hasEndSpace = this.state.label[this.state.label.length - 1] == ' ';
  151. const list = this.state.label.trim().split(' ').filter(label => label != '');
  152. this.state.label = list.slice(0, MAX_LABEL_COUNT).join(' ') + (hasEndSpace && list.length < MAX_LABEL_COUNT ? ' ' : '');
  153. this.state.isPrivate = false;
  154. },
  155. submit() {
  156. if (!this.checkName()) {
  157. // this.$message({
  158. // type: 'info',
  159. // message: this.$t('modelManage.pleaseInputModelName'),
  160. // });
  161. return;
  162. }
  163. const submintApi = this.type == '1' ? modifyModel : saveLocalModel;
  164. submintApi({
  165. repo: location.pathname.split('/').slice(0, 3).join('/'),
  166. ...this.state,
  167. }).then(res => {
  168. res = res.data;
  169. if (res && res.code == '0') {
  170. if (this.type == '1') {
  171. this.goDetail();
  172. return;
  173. }
  174. const list = window.location.href.split('/');
  175. list.pop();
  176. list.push('create_local_model_2');
  177. window.location.href = list.join('/') + '?type=0&name=' + encodeURIComponent(this.state.name) + '&id=' + res.id;
  178. } else if (res && res.code == '-1') {
  179. this.$message({
  180. type: 'error',
  181. message: res.msg,
  182. });
  183. } else {
  184. this.$message({
  185. type: 'error',
  186. message: this.type == '1' ? this.$t('modelManage.modelModifyFailed') : this.$t('modelManage.modelCreateFailed'),
  187. });
  188. }
  189. }).catch(err => {
  190. console.log(err);
  191. });
  192. },
  193. cancel() {
  194. const list = window.location.href.split('/');
  195. list.pop();
  196. list.push('show_model');
  197. window.location.href = list.join('/');
  198. },
  199. goDetail() {
  200. const list = window.location.href.split('/');
  201. list.pop();
  202. list.push('show_model_info');
  203. window.location.href = list.join('/') + '?name=' + encodeURIComponent(this.state.name);
  204. }
  205. },
  206. mounted() {
  207. const urlParams = getUrlSearchParams();
  208. if (urlParams.type == '1' && urlParams.name && urlParams.id) { // update
  209. this.type = urlParams.type;
  210. this.state.name = urlParams.name;
  211. this.state.id = urlParams.id;
  212. this.loading = true;
  213. getModelInfoByName({
  214. repo: location.pathname.split('/').slice(0, 3).join('/'),
  215. name: urlParams.name,
  216. id: urlParams.id
  217. }).then(res => {
  218. this.loading = false;
  219. const list = res.data;
  220. if (list && list.length) {
  221. const data = list[0];
  222. this.state.type = data.type;
  223. this.state.id = data.id;
  224. this.state.name = data.name;
  225. this.state.version = data.version;
  226. this.state.engine = data.engine.toString();
  227. this.state.label = data.label;
  228. this.state.description = data.description;
  229. this.state.isPrivate = data.isPrivate;
  230. }
  231. }).catch(err => {
  232. this.loading = false;
  233. console.log(err);
  234. this.cancel();
  235. });
  236. }
  237. },
  238. beforeDestroy() {
  239. },
  240. };
  241. </script>
  242. <style scoped lang="less">
  243. .header {
  244. height: 45px;
  245. border-color: rgb(212, 212, 213);
  246. border-width: 1px;
  247. border-style: solid;
  248. border-radius: 5px 5px 0px 0px;
  249. font-size: 14px;
  250. background: rgb(240, 240, 240);
  251. display: flex;
  252. align-items: center;
  253. .title {
  254. font-weight: 600;
  255. font-size: 16px;
  256. color: rgb(16, 16, 16);
  257. margin-left: 10px;
  258. }
  259. }
  260. .content {
  261. margin-top: -1px;
  262. border-color: rgb(212, 212, 213);
  263. border-width: 1px;
  264. border-style: solid;
  265. padding: 30px 0;
  266. border-top: none;
  267. .guide-c {
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. margin-bottom: 20px;
  272. .step {
  273. display: flex;
  274. align-items: center;
  275. color: rgb(136, 136, 136);
  276. .num {
  277. border: 1px solid rgb(136, 136, 136);
  278. width: 34px;
  279. height: 34px;
  280. font-size: 24px;
  281. text-align: center;
  282. line-height: 34px;
  283. border-radius: 17px;
  284. margin-right: 8px;
  285. }
  286. .txt {
  287. font-weight: 600;
  288. }
  289. &.focused {
  290. color: rgb(22, 132, 252);
  291. .num {
  292. border-color: rgb(22, 132, 252);
  293. }
  294. }
  295. }
  296. .line {
  297. height: 2px;
  298. width: 50px;
  299. background-color: rgb(187, 187, 187);
  300. margin: 0 10px;
  301. }
  302. }
  303. .row-c {
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. flex-direction: column;
  308. margin: 0 auto;
  309. width: 80%;
  310. .row {
  311. width: 100%;
  312. display: flex;
  313. align-items: center;
  314. margin: 8px 0;
  315. margin-left: -190px;
  316. .r-title {
  317. text-align: right;
  318. font-size: .92857143em;
  319. font-weight: 700;
  320. color: rgba(0, 0, 0, .87);
  321. width: 200px;
  322. margin-right: 28px;
  323. position: relative;
  324. .required {
  325. &::after {
  326. position: absolute;
  327. margin: -0.2em 0 0 0.2em;
  328. content: '*';
  329. color: #db2828;
  330. }
  331. }
  332. }
  333. &.error {
  334. .r-title {
  335. color: #9f3a38;
  336. }
  337. .r-content {
  338. /deep/.el-input__inner {
  339. color: #9f3a38;
  340. background: #fff6f6;
  341. border-color: #e0b4b4;
  342. &::placeholder {
  343. color: #e0b4b4;
  344. }
  345. }
  346. }
  347. }
  348. .r-content {
  349. flex: 1;
  350. .cluster-type-btn {
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. border: 1px solid #DCDFE6;
  355. height: 36px;
  356. padding: 10px;
  357. cursor: pointer;
  358. border-radius: 4px;
  359. .icon {
  360. margin-right: 5px;
  361. }
  362. &.focused {
  363. border-color: rgb(50, 145, 248);
  364. color: rgb(50, 145, 248);
  365. cursor: default;
  366. .icon {
  367. :not([stroke]) {
  368. fill: rgb(50, 145, 248);
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }
  376. }
  377. .input-disabled {
  378. /deep/ .el-input__inner {
  379. background-color: #f5f5f6 !important;
  380. color: #888888 !important;
  381. }
  382. }
  383. .el-select-dropdown__item.selected {
  384. color: rgba(0, 0, 0, .95);
  385. }
  386. /deep/ .el-button {
  387. background-color: #e0e1e2;
  388. color: rgba(0, 0, 0, .6);
  389. border-color: transparent;
  390. transition: opacity .1s ease, background-color .1s ease, color .1s ease, box-shadow .1s ease, background .1s ease, -webkit-box-shadow .1s ease;
  391. will-change: auto;
  392. -webkit-tap-highlight-color: transparent;
  393. &:hover {
  394. border-color: transparent;
  395. background-color: #cacbcd;
  396. color: rgba(0, 0, 0, .8);
  397. }
  398. &:focus {
  399. background-color: #cacbcd;
  400. color: rgba(0, 0, 0, .8);
  401. border-color: transparent;
  402. }
  403. &:active {
  404. background-color: #babbbc;
  405. color: rgba(0, 0, 0, .9);
  406. border-color: transparent;
  407. }
  408. &.green {
  409. background-color: #5bb973;
  410. color: #fff;
  411. &:hover {
  412. background-color: #16ab39;
  413. border-color: transparent;
  414. }
  415. &:focus {
  416. background-color: #0ea432;
  417. border-color: transparent;
  418. }
  419. &:active {
  420. background-color: #198f35;
  421. border-color: transparent;
  422. }
  423. }
  424. }
  425. /deep/ .el-select {
  426. .is-focus {
  427. .el-input__inner {
  428. border-color: #85b7d9;
  429. }
  430. }
  431. }
  432. /deep/ .el-input__inner {
  433. &:focus {
  434. border-color: #85b7d9;
  435. }
  436. }
  437. /deep/ .el-textarea__inner {
  438. &:focus {
  439. border-color: #85b7d9;
  440. }
  441. }
  442. </style>