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

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