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