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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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=""></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. </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 required">
  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. aiCenterList: [...AI_CENTER],
  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. },
  134. getQueueList() {
  135. return getResQueueCode({ cluster: this.dataInfo.Cluster }).then(res => {
  136. res = res.data;
  137. if (res.Code === 0) {
  138. const data = res.Data;
  139. const list = [];
  140. for (let i = 0, iLen = data.length; i < iLen; i++) {
  141. const item = data[i];
  142. list.push({
  143. k: item.ID,
  144. v: `${item.QueueCode}(${getListValueWithKey(this.clusterList, item.Cluster)} - ${getListValueWithKey(this.aiCenterList, item.AiCenterCode)})`,
  145. });
  146. }
  147. this.queueList.splice(0, Infinity, ...list);
  148. if (this.queueList.length === 0) {
  149. this.changeQueue();
  150. }
  151. }
  152. }).catch(err => {
  153. console.log(err);
  154. });
  155. },
  156. getResSpecificationList() {
  157. const params = {
  158. cluster: this.dataInfo.Cluster,
  159. queue: this.dataInfo.QueueId,
  160. status: 2,
  161. page: 1,
  162. };
  163. getResSpecificationList(params).then(res => {
  164. res = res.data;
  165. if (res.Code === 0) {
  166. const list = res.Data.List;
  167. const data = list.map((item) => {
  168. const Queue = item.Queue;
  169. const Spec = item.Spec;
  170. const NGPU = `${Queue.ComputeResource}:${Spec.AccCardsNum === 0 ? '0' : Spec.AccCardsNum + '*' + getListValueWithKey(this.accCardTypeList, Queue.AccCardType)}`;
  171. return {
  172. k: Spec.ID,
  173. 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')}`,
  174. }
  175. });
  176. this.specsList.splice(0, Infinity, ...data);
  177. }
  178. }).catch(err => {
  179. console.log(err);
  180. });
  181. },
  182. changeIsExclusive() {
  183. this.dataInfo.ExclusiveOrg = '';
  184. },
  185. changeCluster() {
  186. this.dataInfo.QueueId = '';
  187. this.dataInfo.SpecIds = [];
  188. this.queueList.splice(0, Infinity);
  189. this.specsList.splice(0, Infinity);
  190. this.getQueueList();
  191. },
  192. changeQueue() {
  193. this.dataInfo.SpecIds = [];
  194. this.specsList.splice(0, Infinity);
  195. this.getResSpecificationList();
  196. },
  197. open() {
  198. this.resetDataInfo();
  199. if (this.type === 'add') {
  200. //
  201. } else if (this.type === 'edit') {
  202. this.dataInfo = Object.assign(this.dataInfo, { ...this.data });
  203. this.queueList.splice(0, Infinity);
  204. this.specsList.splice(0, Infinity);
  205. this.getQueueList().then(() => {
  206. this.getResSpecificationList();
  207. });
  208. }
  209. this.$emit("open");
  210. },
  211. opened() {
  212. this.$emit("opened");
  213. },
  214. close() {
  215. this.$emit("close");
  216. },
  217. closed() {
  218. this.$emit("closed");
  219. this.$emit("update:visible", false);
  220. },
  221. confirm() {
  222. if (!this.dataInfo.SceneName || !this.dataInfo.JobType || !this.dataInfo.QueueId || !this.dataInfo.SpecIds.length || (this.dataInfo.IsExclusive === '1' && !this.dataInfo.ExclusiveOrg)) {
  223. this.$message({
  224. type: 'info',
  225. message: this.$t('pleaseCompleteTheInformationFirst')
  226. });
  227. return;
  228. }
  229. const setApi = this.type === 'add' ? addResScene : updateResScene;
  230. setApi({
  231. ...this.dataInfo,
  232. action: this.type === 'edit' ? 'edit' : undefined,
  233. IsExclusive: this.dataInfo.IsExclusive === '1',
  234. }).then(res => {
  235. res = res.data;
  236. if (res.Code === 0) {
  237. this.$message({
  238. type: 'success',
  239. message: this.$t('submittedSuccessfully')
  240. });
  241. this.$emit("confirm");
  242. } else {
  243. this.$message({
  244. type: 'error',
  245. message: this.$t('submittedFailed')
  246. });
  247. }
  248. }).catch(err => {
  249. console.log(err);
  250. this.$message({
  251. type: 'error',
  252. message: this.$t('submittedFailed')
  253. });
  254. })
  255. },
  256. cancel() {
  257. this.dialogShow = false;
  258. this.$emit("update:visible", false);
  259. }
  260. },
  261. mounted() {
  262. this.resetDataInfo();
  263. },
  264. };
  265. </script>
  266. <style scoped lang="less">
  267. .dlg-content {
  268. margin: 20px 0 25px 0;
  269. display: flex;
  270. justify-content: center;
  271. .form {
  272. width: 600px;
  273. .form-row {
  274. display: flex;
  275. min-height: 42px;
  276. margin-bottom: 4px;
  277. .title {
  278. width: 160px;
  279. display: flex;
  280. justify-content: flex-end;
  281. align-items: center;
  282. margin-right: 20px;
  283. color: rgb(136, 136, 136);
  284. font-size: 14px;
  285. &.required {
  286. span {
  287. position: relative;
  288. }
  289. span::after {
  290. position: absolute;
  291. right: -10px;
  292. top: -2px;
  293. vertical-align: top;
  294. content: '*';
  295. color: #db2828;
  296. }
  297. }
  298. }
  299. .content {
  300. width: 300px;
  301. display: flex;
  302. align-items: center;
  303. /deep/ .el-select {
  304. width: 100%;
  305. }
  306. }
  307. .specSel {
  308. /deep/ .el-tag.el-tag--info {
  309. max-width: 81%;
  310. display: flex;
  311. align-items: center;
  312. .el-select__tags-text {
  313. overflow: hidden;
  314. text-overflow: ellipsis;
  315. }
  316. .el-tag__close {
  317. flex-shrink: 0;
  318. right: -5px;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. .btn {
  325. color: rgb(2, 0, 4);
  326. background-color: rgb(194, 199, 204);
  327. border-color: rgb(194, 199, 204);
  328. &.confirm-btn {
  329. color: #fff;
  330. background-color: rgb(56, 158, 13);
  331. border-color: rgb(56, 158, 13);
  332. }
  333. }
  334. }
  335. .el-select-dropdown__item {
  336. padding-left: 26px !important;
  337. }
  338. .el-select-dropdown__item.selected::after {
  339. right: 0;
  340. left: 6px;
  341. }
  342. </style>