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 12 kB

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