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