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.

SceneDialog.vue 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div class="base-dlg">
  3. <BaseDialog :visible.sync="dialogShow" :width="`750px`"
  4. :title="type === 'add' ? $t('resourcesManagement.addResScene') : $t('resourcesManagement.editResScene')"
  5. @open="open" @opened="opened" @close="close" @closed="closed">
  6. <div class="dlg-content">
  7. <div class="form">
  8. <div class="form-row">
  9. <div class="title required">
  10. <span>{{ $t('resourcesManagement.resSceneName') }}</span>
  11. </div>
  12. <div class="content">
  13. <el-input v-model="dataInfo.SceneName" placeholder="" maxlength="255"></el-input>
  14. </div>
  15. </div>
  16. <div class="form-row">
  17. <div class="title required">
  18. <span>{{ $t('resourcesManagement.jobType') }}</span>
  19. </div>
  20. <div class="content">
  21. <el-select v-model="dataInfo.JobType" :disabled="type === 'edit'">
  22. <el-option v-for="item in taskTypeList" :key="item.k" :label="item.v" :value="item.k" />
  23. </el-select>
  24. </div>
  25. </div>
  26. <div class="form-row">
  27. <div class="title required">
  28. <span>{{ $t('resourcesManagement.isExclusive') }}</span>
  29. </div>
  30. <div class="content">
  31. <el-select v-model="dataInfo.IsExclusive" @change="changeIsExclusive">
  32. <el-option v-for="item in isExclusiveList" :key="item.k" :label="item.v" :value="item.k" />
  33. </el-select>
  34. </div>
  35. </div>
  36. <div class="form-row" v-if="dataInfo.IsExclusive === '1'">
  37. <div class="title required">
  38. <span>{{ $t('resourcesManagement.exclusiveOrg') }}</span>
  39. </div>
  40. <div class="content">
  41. <el-input v-model="dataInfo.ExclusiveOrg" :placeholder="$t('resourcesManagement.exclusiveOrgTips')"
  42. maxlength="255">
  43. </el-input>
  44. </div>
  45. </div>
  46. <div class="form-row">
  47. <div class="title required">
  48. <span>{{ $t('resourcesManagement.computeCluster') }}</span>
  49. </div>
  50. <div class="content">
  51. <el-select v-model="dataInfo.Cluster" @change="changeCluster" :disabled="type === 'edit'">
  52. <el-option v-for="item in clusterList" :key="item.k" :label="item.v" :value="item.k" />
  53. </el-select>
  54. </div>
  55. </div>
  56. <div class="form-row">
  57. <div class="title">
  58. <span>{{ $t('resourcesManagement.resQueue') }}</span>
  59. </div>
  60. <div class="content">
  61. <el-select v-model="dataInfo.QueueId" @change="changeQueue" :disabled="type === 'edit'">
  62. <el-option v-for="item in queueList" :key="item.k" :label="item.v" :value="item.k" />
  63. </el-select>
  64. </div>
  65. </div>
  66. <div class="form-row">
  67. <div class="title required">
  68. <span>{{ $t('resourcesManagement.resourceSpecification') }}</span>
  69. </div>
  70. <div class="content">
  71. <el-select v-model="dataInfo.SpecIds" multiple collapse-tags class="specSel">
  72. <el-option v-for="item in specsList" :key="item.k" :label="item.v" :value="item.k" />
  73. </el-select>
  74. </div>
  75. </div>
  76. <div class="form-row" style="margin-top: 20px">
  77. <div class="title"></div>
  78. <div class="content">
  79. <el-button type="primary" class="btn confirm-btn" @click="confirm">{{ $t('confirm') }}</el-button>
  80. <el-button class="btn" @click="cancel">{{ $t('cancel') }}</el-button>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </BaseDialog>
  86. </div>
  87. </template>
  88. <script>
  89. import BaseDialog from '~/components/BaseDialog.vue';
  90. import { getResQueueCode, getResSpecificationList, addResScene, updateResScene } from '~/apis/modules/resources';
  91. import { JOB_TYPE, CLUSTERS, AI_CENTER, ACC_CARD_TYPE, SPECIFICATION_STATUS } from '~/const';
  92. import { getListValueWithKey } from '~/utils';
  93. export default {
  94. name: "SceneDialog",
  95. props: {
  96. visible: { type: Boolean, default: false },
  97. title: { type: String, default: '' },
  98. type: { type: String, defalut: 'add' },
  99. data: { type: Object, default: () => ({}) },
  100. },
  101. components: {
  102. BaseDialog
  103. },
  104. data() {
  105. return {
  106. dialogShow: false,
  107. dataInfo: {},
  108. taskTypeList: [...JOB_TYPE],
  109. clusterList: [...CLUSTERS],
  110. accCardTypeList: [...ACC_CARD_TYPE],
  111. statusList: [...SPECIFICATION_STATUS],
  112. isExclusiveList: [{ k: '2', v: this.$t('resourcesManagement.commonUse') }, { k: '1', v: this.$t('resourcesManagement.exclusive') }],
  113. queueList: [],
  114. specsList: [],
  115. };
  116. },
  117. watch: {
  118. visible: function (val) {
  119. this.dialogShow = val;
  120. },
  121. },
  122. methods: {
  123. resetDataInfo() {
  124. this.dataInfo = {
  125. SceneName: '',
  126. JobType: '',
  127. IsExclusive: '2',
  128. ExclusiveOrg: '',
  129. Cluster: '',
  130. QueueId: '',
  131. SpecIds: [],
  132. }
  133. this.queueList.splice(0, Infinity);
  134. this.specsList.splice(0, Infinity);
  135. },
  136. getQueueList(next) {
  137. return getResQueueCode({ cluster: this.dataInfo.Cluster }).then(res => {
  138. res = res.data;
  139. if (res.Code === 0) {
  140. const data = res.Data;
  141. const list = [];
  142. for (let i = 0, iLen = data.length; i < iLen; i++) {
  143. const item = data[i];
  144. list.push({
  145. k: item.ID,
  146. v: `${item.QueueCode}(${getListValueWithKey(this.clusterList, item.Cluster)} - ${item.AiCenterName})`,
  147. });
  148. }
  149. list.unshift({
  150. k: '-1',
  151. v: this.$t('resourcesManagement.allResQueue'),
  152. });
  153. this.queueList.splice(0, Infinity, ...list);
  154. if (next) {
  155. if (this.type === 'add') {
  156. this.dataInfo.QueueId = '-1';
  157. }
  158. this.getResSpecificationList();
  159. }
  160. }
  161. }).catch(err => {
  162. console.log(err);
  163. });
  164. },
  165. getResSpecificationList() {
  166. const params = {
  167. cluster: this.dataInfo.Cluster,
  168. queue: this.dataInfo.QueueId === '-1' ? '' : this.dataInfo.QueueId,
  169. status: 2,
  170. page: 1,
  171. };
  172. return getResSpecificationList(params).then(res => {
  173. res = res.data;
  174. if (res.Code === 0) {
  175. const list = res.Data.List;
  176. const data = list.map((item) => {
  177. const Queue = item.Queue;
  178. const Spec = item.Spec;
  179. const NGPU = `${Queue.ComputeResource}:${Spec.AccCardsNum === 0 ? '0' : Spec.AccCardsNum + '*' + getListValueWithKey(this.accCardTypeList, Queue.AccCardType)}`;
  180. return {
  181. k: Spec.ID,
  182. v: `${NGPU}, CPU:${Spec.CpuCores}, ${this.$t('resourcesManagement.gpuMem')}:${Spec.GPUMemGiB}GB, ${this.$t('resourcesManagement.mem')}:${Spec.MemGiB}GB, ${this.$t('resourcesManagement.shareMem')}:${Spec.ShareMemGiB}GB, ${this.$t('resourcesManagement.unitPrice')}:${Spec.UnitPrice}${this.$t('resourcesManagement.point_hr')}`,
  183. }
  184. });
  185. this.specsList.splice(0, Infinity, ...data);
  186. }
  187. }).catch(err => {
  188. console.log(err);
  189. });
  190. },
  191. changeIsExclusive() {
  192. this.dataInfo.ExclusiveOrg = '';
  193. },
  194. changeCluster() {
  195. this.dataInfo.QueueId = '';
  196. this.dataInfo.SpecIds = [];
  197. this.queueList.splice(0, Infinity);
  198. this.specsList.splice(0, Infinity);
  199. this.getQueueList(true);
  200. },
  201. changeQueue() {
  202. this.dataInfo.SpecIds = [];
  203. this.specsList.splice(0, Infinity);
  204. this.getResSpecificationList();
  205. },
  206. open() {
  207. this.resetDataInfo();
  208. if (this.type === 'add') {
  209. //
  210. } else if (this.type === 'edit') {
  211. Object.assign(this.dataInfo, { ...this.data, QueueId: this.data.QueueIds.length === 1 ? this.data.QueueIds[0] : '-1' });
  212. this.queueList.splice(0, Infinity);
  213. this.specsList.splice(0, Infinity);
  214. this.getQueueList(true);
  215. }
  216. this.$emit("open");
  217. },
  218. opened() {
  219. this.$emit("opened");
  220. },
  221. close() {
  222. this.$emit("close");
  223. },
  224. closed() {
  225. this.$emit("closed");
  226. this.$emit("update:visible", false);
  227. },
  228. confirm() {
  229. if (!this.dataInfo.SceneName || !this.dataInfo.JobType || !this.dataInfo.SpecIds.length || (this.dataInfo.IsExclusive === '1' && !this.dataInfo.ExclusiveOrg)) {
  230. this.$message({
  231. type: 'info',
  232. message: this.$t('pleaseCompleteTheInformationFirst')
  233. });
  234. return;
  235. }
  236. const setApi = this.type === 'add' ? addResScene : updateResScene;
  237. setApi({
  238. ...this.dataInfo,
  239. action: this.type === 'edit' ? 'edit' : undefined,
  240. IsExclusive: this.dataInfo.IsExclusive === '1',
  241. }).then(res => {
  242. res = res.data;
  243. if (res.Code === 0) {
  244. this.$message({
  245. type: 'success',
  246. message: this.$t('submittedSuccessfully')
  247. });
  248. this.$emit("confirm");
  249. } else {
  250. this.$message({
  251. type: 'error',
  252. message: this.$t('submittedFailed')
  253. });
  254. }
  255. }).catch(err => {
  256. console.log(err);
  257. this.$message({
  258. type: 'error',
  259. message: this.$t('submittedFailed')
  260. });
  261. })
  262. },
  263. cancel() {
  264. this.dialogShow = false;
  265. this.$emit("update:visible", false);
  266. }
  267. },
  268. mounted() {
  269. this.resetDataInfo();
  270. },
  271. };
  272. </script>
  273. <style scoped lang="less">
  274. .dlg-content {
  275. margin: 20px 0 25px 0;
  276. display: flex;
  277. justify-content: center;
  278. .form {
  279. width: 600px;
  280. .form-row {
  281. display: flex;
  282. min-height: 42px;
  283. margin-bottom: 4px;
  284. .title {
  285. width: 160px;
  286. display: flex;
  287. justify-content: flex-end;
  288. align-items: center;
  289. margin-right: 20px;
  290. color: rgb(136, 136, 136);
  291. font-size: 14px;
  292. &.required {
  293. span {
  294. position: relative;
  295. }
  296. span::after {
  297. position: absolute;
  298. right: -10px;
  299. top: -2px;
  300. vertical-align: top;
  301. content: '*';
  302. color: #db2828;
  303. }
  304. }
  305. }
  306. .content {
  307. width: 300px;
  308. display: flex;
  309. align-items: center;
  310. /deep/ .el-select {
  311. width: 100%;
  312. }
  313. }
  314. .specSel {
  315. /deep/ .el-tag.el-tag--info {
  316. max-width: 81%;
  317. display: flex;
  318. align-items: center;
  319. .el-select__tags-text {
  320. overflow: hidden;
  321. text-overflow: ellipsis;
  322. }
  323. .el-tag__close {
  324. flex-shrink: 0;
  325. right: -5px;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. .btn {
  332. color: rgb(2, 0, 4);
  333. background-color: rgb(194, 199, 204);
  334. border-color: rgb(194, 199, 204);
  335. &.confirm-btn {
  336. color: #fff;
  337. background-color: rgb(56, 158, 13);
  338. border-color: rgb(56, 158, 13);
  339. }
  340. }
  341. }
  342. .el-select-dropdown__item {
  343. padding-left: 26px !important;
  344. }
  345. .el-select-dropdown__item.selected::after {
  346. right: 0;
  347. left: 6px;
  348. }
  349. </style>