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.

selectImages.vue 17 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <div
  3. class="inline required field"
  4. :class="{ min_title: benchmarkNew, unite: benchmark }"
  5. >
  6. <label
  7. v-if="benchmarkNew"
  8. class="label-fix-width"
  9. style="font-weight: normal"
  10. >{{i18n.image_label}}</label
  11. >
  12. <label v-else>{{i18n.image_label}}</label>
  13. <input
  14. v-if="benchmarkNew"
  15. type="text"
  16. name="image"
  17. :value="imageAddress"
  18. style="width: 48.5%"
  19. :placeholder="i18n.image_select_placeholder"
  20. required
  21. />
  22. <input
  23. v-else
  24. type="text"
  25. name="image"
  26. :value="imageAddress"
  27. :placeholder="i18n.image_select_placeholder"
  28. required
  29. />
  30. <el-button
  31. type="text"
  32. @click="dialogVisible = true"
  33. icon="el-icon-plus"
  34. style="color: #0366d6"
  35. >{{i18n.image_select}}
  36. </el-button>
  37. <el-dialog :title="i18n.image_select" :visible.sync="dialogVisible" width="50%">
  38. <div
  39. class="ui icon input"
  40. style="z-index: 9999; position: absolute; right: 50px; height: 30px"
  41. >
  42. <i
  43. class="search icon"
  44. style="cursor: pointer; pointer-events: auto"
  45. ></i>
  46. <input
  47. type="text"
  48. :placeholder="i18n.image_search_placeholder"
  49. v-model="search"
  50. @keydown.enter.stop.prevent="searchName"
  51. />
  52. </div>
  53. <el-tabs v-model="activeName" @tab-click="handleClick">
  54. <el-tab-pane :label="i18n.image_public" name="first" v-loading="loadingPublic">
  55. <div
  56. style="
  57. display: flex;
  58. align-items: center;
  59. justify-content: space-between;
  60. padding: 1rem 0;
  61. border-bottom: 1px solid #f5f5f5;
  62. "
  63. v-for="(publicData, index) in tableDataPublic"
  64. :key="index"
  65. >
  66. <div style="width: 90%">
  67. <div
  68. style="
  69. display: flex;
  70. align-items: center;
  71. justify-content: space-between;
  72. "
  73. >
  74. <div style="display: flex; align-items: center">
  75. <span
  76. class="panel_dataset_name text-over"
  77. style="margin-left: 0"
  78. >{{ publicData.tag }}
  79. </span>
  80. <img
  81. v-if="publicData.type == 5"
  82. src="/img/jian.svg"
  83. style="margin-left: 0.5rem"
  84. />
  85. </div>
  86. <div v-if="!!publicData.topics" class="text-over">
  87. <span
  88. v-for="(topic, index) in publicData.topics"
  89. class="ui repo-topic label topic"
  90. >{{ topic }}</span
  91. >
  92. </div>
  93. </div>
  94. <div style="margin-top: 8px; display: flex">
  95. <a
  96. v-if="publicData.relAvatarLink || publicData.userName"
  97. :title="publicData.userName"
  98. style="cursor: default"
  99. >
  100. <img
  101. class="ui avatar mini image"
  102. style="width: 20px; height: 20px"
  103. :src="publicData.relAvatarLink"
  104. />
  105. </a>
  106. <a v-else
  107. ><img
  108. class="ui avatar mini image"
  109. title="Ghost"
  110. src="/user/avatar/ghost/-1"
  111. style="width: 20px; height: 20px"
  112. /></a>
  113. <span class="panel_datset_desc">{{
  114. publicData.description
  115. }}</span>
  116. </div>
  117. </div>
  118. <div>
  119. <button
  120. class="ui primary basic button mini"
  121. @click.stop.prevent="
  122. selectImages(publicData.place, publicData.tag)
  123. "
  124. >
  125. {{i18n.image_use}}
  126. </button>
  127. </div>
  128. </div>
  129. <div
  130. class="ui container"
  131. style="margin-top: 50px; text-align: center"
  132. >
  133. <el-pagination
  134. background
  135. @current-change="handleCurrentChangePublic"
  136. :current-page="currentPagePublic"
  137. :page-size="pageSizePublic"
  138. layout="total, prev, pager, next"
  139. :total="totalNumPublic"
  140. >
  141. </el-pagination>
  142. </div>
  143. </el-tab-pane>
  144. <el-tab-pane :label="i18n.image_my" name="second" v-loading="loadingCustom">
  145. <div
  146. style="
  147. display: flex;
  148. align-items: center;
  149. justify-content: space-between;
  150. padding: 1rem 0;
  151. border-bottom: 1px solid #f5f5f5;
  152. "
  153. v-for="(customData, index) in tableDataCustom"
  154. :key="index"
  155. >
  156. <div style="width: 90%">
  157. <div
  158. style="
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-between;
  162. "
  163. >
  164. <span
  165. class="panel_dataset_name text-over"
  166. style="margin-left: 0"
  167. >{{ customData.tag }}
  168. </span>
  169. <div v-if="!!customData.topics" class="text-over">
  170. <span
  171. v-for="(topic, index) in customData.topics"
  172. class="ui repo-topic label topic"
  173. >{{ topic }}</span
  174. >
  175. </div>
  176. </div>
  177. <div style="margin-top: 8px; display: flex">
  178. <a
  179. v-if="customData.relAvatarLink || customData.userName"
  180. :title="customData.userName"
  181. style="cursor: default"
  182. >
  183. <img
  184. class="ui avatar mini image"
  185. style="width: 20px; height: 20px"
  186. :src="customData.relAvatarLink"
  187. />
  188. </a>
  189. <a v-else
  190. ><img
  191. class="ui avatar mini image"
  192. title="Ghost"
  193. src="/user/avatar/ghost/-1"
  194. style="width: 20px; height: 20px"
  195. /></a>
  196. <span class="panel_datset_desc">{{
  197. customData.description
  198. }}</span>
  199. </div>
  200. </div>
  201. <div>
  202. <button
  203. v-if="customData.status === 1"
  204. class="ui primary basic button mini"
  205. @click.stop.prevent="
  206. selectImages(customData.place, customData.tag)
  207. "
  208. >
  209. {{i18n.image_use}}
  210. </button>
  211. <span
  212. v-if="customData.status === 0"
  213. style="display: flex; align-items: center"
  214. >
  215. <i class="CREATING"></i>
  216. <span
  217. style="margin-left: 0.4em; font-size: 12px; color: #5a5a5a"
  218. >{{i18n.image_commit}}</span
  219. >
  220. </span>
  221. <span
  222. v-if="customData.status === 2"
  223. style="display: flex; align-items: center"
  224. >
  225. <i class="FAILED"></i>
  226. <el-tooltip
  227. class="item"
  228. effect="dark"
  229. :content="i18n.image_commit_content"
  230. placement="left"
  231. >
  232. <span style="margin-left: 0.4em; font-size: 12px; color: red"
  233. >{{i18n.image_commit_failed}}</span
  234. >
  235. </el-tooltip>
  236. </span>
  237. </div>
  238. </div>
  239. <div
  240. class="ui container"
  241. style="margin-top: 50px; text-align: center"
  242. >
  243. <el-pagination
  244. background
  245. @current-change="handleCurrentChangeCustom"
  246. :current-page="currentPageCustom"
  247. :page-size="pageSizeCustom"
  248. layout="total, prev, pager, next"
  249. :total="totalNumCustom"
  250. >
  251. </el-pagination>
  252. </div>
  253. </el-tab-pane>
  254. <el-tab-pane :label="i18n.image_collected" name="third">
  255. <div
  256. style="
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. padding: 1rem 0;
  261. border-bottom: 1px solid #f5f5f5;
  262. "
  263. v-for="(starData, index) in tableDataStar"
  264. :key="index"
  265. >
  266. <div style="width: 90%">
  267. <div
  268. style="
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. "
  273. >
  274. <div style="display: flex; align-items: center">
  275. <span
  276. class="panel_dataset_name text-over"
  277. style="margin-left: 0"
  278. >{{ starData.tag }}
  279. </span>
  280. <img
  281. v-if="starData.type == 5"
  282. src="/img/jian.svg"
  283. style="margin-left: 0.5rem"
  284. />
  285. </div>
  286. <div v-if="!!starData.topics" class="text-over">
  287. <span
  288. v-for="(topic, index) in starData.topics"
  289. class="ui repo-topic label topic"
  290. >{{ topic }}</span
  291. >
  292. </div>
  293. </div>
  294. <div style="margin-top: 8px; display: flex">
  295. <a
  296. v-if="starData.relAvatarLink || starData.userName"
  297. :title="starData.userName"
  298. style="cursor: default"
  299. >
  300. <img
  301. class="ui avatar mini image"
  302. style="width: 20px; height: 20px"
  303. :src="starData.relAvatarLink"
  304. />
  305. </a>
  306. <a v-else
  307. ><img
  308. class="ui avatar mini image"
  309. title="Ghost"
  310. src="/user/avatar/ghost/-1"
  311. style="width: 20px; height: 20px"
  312. /></a>
  313. <span class="panel_datset_desc">{{
  314. starData.description
  315. }}</span>
  316. </div>
  317. </div>
  318. <div>
  319. <button
  320. class="ui primary basic button mini"
  321. @click.stop.prevent="selectImages(starData.place, starData.tag)"
  322. >
  323. {{i18n.image_use}}
  324. </button>
  325. </div>
  326. </div>
  327. <div
  328. class="ui container"
  329. style="margin-top: 50px; text-align: center"
  330. >
  331. <el-pagination
  332. background
  333. @current-change="handleCurrentChangeStar"
  334. :current-page="currentPageStar"
  335. :page-size="pageSizeStar"
  336. layout="total, prev, pager, next"
  337. :total="totalNumStar"
  338. >
  339. </el-pagination>
  340. </div>
  341. </el-tab-pane>
  342. </el-tabs>
  343. </el-dialog>
  344. </div>
  345. </template>
  346. <script>
  347. const { _AppSubUrl, _StaticUrlPrefix, csrf } = window.config;
  348. export default {
  349. components: {},
  350. data() {
  351. return {
  352. dialogVisible: false,
  353. benchmarkNew: false,
  354. benchmark: false,
  355. imageAddress: "",
  356. activeName: "first",
  357. search: "",
  358. checked: false,
  359. currentPagePublic: 1,
  360. pageSizePublic: 5,
  361. totalNumPublic: 0,
  362. paramsPublic: { page: 1, pageSize: 5, q: "", recommend: false },
  363. tableDataPublic: [],
  364. loadingPublic: false,
  365. i18n: {},
  366. currentPageCustom: 1,
  367. pageSizeCustom: 5,
  368. totalNumCustom: 0,
  369. paramsCustom: { page: 1, pageSize: 5, q: "" },
  370. tableDataCustom: [],
  371. starCustom: [],
  372. loadingCustom: false,
  373. currentPageStar: 1,
  374. pageSizeStar: 5,
  375. totalNumStar: 0,
  376. paramsStar: { page: 1, pageSize: 5, q: "" },
  377. tableDataStar: [],
  378. loadingStar: false,
  379. };
  380. },
  381. methods: {
  382. handleClick(tab, event) {
  383. this.search = "";
  384. if (tab.name == "first") {
  385. this.paramsPublic.q = "";
  386. this.getImageListPublic();
  387. }
  388. if (tab.name == "second") {
  389. this.getImageListCustom();
  390. }
  391. if (tab.name == "third") {
  392. this.getImageListStar();
  393. }
  394. },
  395. tableHeaderStyle({ row, column, rowIndex, columnIndex }) {
  396. if (rowIndex === 0) {
  397. return "background:#f5f5f6;color:#606266";
  398. }
  399. },
  400. handleCurrentChangePublic(val) {
  401. this.paramsPublic.page = val;
  402. this.getImageListPublic();
  403. },
  404. handleCurrentChangeCustom(val) {
  405. this.paramsCustom.page = val;
  406. this.getImageListCustom();
  407. },
  408. handleCurrentChangeStar(val) {
  409. this.paramsStar.page = val;
  410. this.getImageListStar();
  411. },
  412. getImageListPublic() {
  413. this.loadingPublic = true;
  414. this.$axios
  415. .get("/explore/images/public", {
  416. params: this.paramsPublic,
  417. })
  418. .then((res) => {
  419. this.totalNumPublic = res.data.count;
  420. this.tableDataPublic = res.data.images;
  421. this.loadingPublic = false;
  422. });
  423. },
  424. getImageListCustom() {
  425. this.loadingCustom = true;
  426. this.$axios
  427. .get("/explore/images/custom", {
  428. params: this.paramsCustom,
  429. })
  430. .then((res) => {
  431. this.totalNumCustom = res.data.count;
  432. this.tableDataCustom = res.data.images;
  433. this.tableDataCustom.forEach((element) => {
  434. this.starCustom.push({ id: element.id });
  435. });
  436. this.loadingCustom = false;
  437. });
  438. },
  439. getImageListStar() {
  440. this.loadingStar = true;
  441. this.$axios
  442. .get("/explore/images/star", {
  443. params: this.paramsStar,
  444. })
  445. .then((res) => {
  446. this.totalNumStar = res.data.count;
  447. this.tableDataStar = res.data.images;
  448. this.loadingStar = false;
  449. });
  450. },
  451. searchName() {
  452. if (this.activeName == "first") {
  453. this.paramsPublic.q = this.search;
  454. this.paramsPublic.page = 1;
  455. this.getImageListPublic();
  456. }
  457. if (this.activeName == "second") {
  458. this.paramsCustom.q = this.search;
  459. this.paramsCustom.page = 1;
  460. this.getImageListCustom();
  461. }
  462. if (this.activeName == "third") {
  463. this.paramsStar.q = this.search;
  464. this.paramsStar.page = 1;
  465. this.getImageListStar();
  466. }
  467. },
  468. selectImages(place) {
  469. this.imageAddress = place;
  470. this.dialogVisible = false;
  471. },
  472. },
  473. watch: {
  474. search(val) {
  475. if (this.activeName == "first") {
  476. this.paramsPublic.q = val;
  477. this.getImageListPublic();
  478. }
  479. if (this.activeName == "second") {
  480. this.paramsCustom.q = val;
  481. this.getImageListCustom();
  482. }
  483. if (this.activeName == "third") {
  484. this.paramsStar.q = val;
  485. this.getImageListStar();
  486. }
  487. },
  488. },
  489. mounted() {
  490. if (document.getElementById("ai_image_name")) {
  491. this.imageAddress = document.getElementById("ai_image_name").value;
  492. }
  493. this.getImageListPublic();
  494. if (
  495. location.href.indexOf("train-job") !== -1 ||
  496. location.href.indexOf("inference-job") !== -1 ||
  497. location.href.indexOf("benchmark") !== -1 ||
  498. location.href.indexOf("modelsafety") !== -1
  499. ) {
  500. this.benchmarkNew = true;
  501. }
  502. if (location.href.indexOf("cloudbrain/benchmark/") !== -1) {
  503. this.benchmark = true;
  504. }
  505. },
  506. created() {
  507. if (document.documentElement.attributes["lang"].nodeValue == "en-US") {
  508. this.i18n = this.$locale.US;
  509. } else {
  510. this.i18n = this.$locale.CN;
  511. }
  512. },
  513. };
  514. </script>
  515. <style scoped>
  516. .header-wrapper {
  517. background-color: #f5f5f6;
  518. padding-top: 15px;
  519. }
  520. .image_text {
  521. padding: 25px 0 55px 0;
  522. }
  523. #header {
  524. position: relative;
  525. top: -40px;
  526. }
  527. #success {
  528. background-color: #5bb973;
  529. color: white;
  530. }
  531. .text-over {
  532. overflow: hidden;
  533. text-overflow: ellipsis;
  534. vertical-align: middle;
  535. white-space: nowrap;
  536. }
  537. .image_title {
  538. display: inline-block;
  539. width: 80%;
  540. cursor: default;
  541. color: rgb(66, 98, 144);
  542. }
  543. .image_desc {
  544. -webkit-line-clamp: 2;
  545. -webkit-box-orient: vertical;
  546. display: -webkit-box;
  547. text-overflow: ellipsis;
  548. overflow: hidden;
  549. }
  550. .heart-stroke {
  551. stroke: #666;
  552. stroke-width: 2;
  553. fill: #fff;
  554. }
  555. .stars_active {
  556. fill: #fa8c16 !important;
  557. stroke: #fa8c16 !important;
  558. }
  559. </style>