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.

referenceDataset.vue 20 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
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
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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <div>
  3. <template v-if="showFlag">
  4. <div class="ui container">
  5. <div class="ui mobile reversed stackable grid">
  6. <div class="row" style="justify-content: space-between">
  7. <div class="ui blue small menu compact selectcloudbrain">
  8. <a class="item" :href="`${repoLink}/datasets`">{{
  9. i18n.current_dataset
  10. }}</a>
  11. <a
  12. class="active item"
  13. :href="`${repoLink}/datasets/reference_datasets`"
  14. >{{ i18n.linked_datasets }}</a
  15. >
  16. </div>
  17. <button
  18. style="margin-right: 2rem"
  19. class="ui green button"
  20. @click="openDataset()"
  21. >
  22. {{ i18n.linked_datasets }}
  23. </button>
  24. </div>
  25. <div class="row">
  26. <div class="ui two cards" style="width: 100%">
  27. <div
  28. class="ui card refer-dataset-card"
  29. v-for="(item, index) in datasetList"
  30. :key="index"
  31. @click="gotoDataset(item)"
  32. >
  33. <div class="content" style="border-bottom: none">
  34. <div class="refer-dataset-card-content">
  35. <div class="refer-dataset-card-title">
  36. <span
  37. :title="item.Title"
  38. class="nowrap"
  39. style="display: inline-block; max-width: 90%"
  40. >{{ item.Title }}</span
  41. ><img
  42. v-if="item.Recommend"
  43. src="/img/jian.svg"
  44. style="margin-left: 0.5rem"
  45. />
  46. </div>
  47. <template v-if="item.IsStaring">
  48. <div style="display: flex">
  49. <button
  50. class="ui mini basic button dataset-card-flavor"
  51. @click.stop="postStar(item)"
  52. >
  53. <i class="ri-heart-fill" style="color: #fa8c16"></i>
  54. <span style="margin-left: 0.3rem">{{
  55. i18n.unfavorite
  56. }}</span>
  57. </button>
  58. <a class="ui mini basic button card-flavor-num">
  59. {{ item.NumStars }}
  60. </a>
  61. </div>
  62. </template>
  63. <template v-else>
  64. <div style="display: flex">
  65. <button
  66. class="ui mini basic button dataset-card-flavor"
  67. @click.stop="postStar(item)"
  68. >
  69. <i class="ri-heart-line"></i>
  70. <span style="margin-left: 0.3rem">{{
  71. i18n.favorite
  72. }}</span>
  73. </button>
  74. <a class="ui mini basic button card-flavor-num">
  75. {{ item.NumStars }}
  76. </a>
  77. </div>
  78. </template>
  79. </div>
  80. <div style="font-size: 12px; margin-top: 5px">
  81. <a
  82. v-if="item.Category"
  83. :href="'/explore/datasets?category=' + item.Category"
  84. class="ui repo-topic label topic"
  85. >{{ i18n[item.Category] || item.Category }}</a
  86. >
  87. <a
  88. v-if="item.Task"
  89. :href="'/explore/datasets?task=' + item.Task"
  90. class="ui repo-topic label topic"
  91. >{{ i18n[item.Task] || item.Task }}</a
  92. >
  93. <a
  94. v-if="item.License"
  95. :href="'/explore/datasets?license=' + item.License"
  96. class="ui repo-topic label topic"
  97. >{{ item.License }}</a
  98. >
  99. </div>
  100. <div class="description card-flavor-desc">
  101. <p>{{ item.Description }}</p>
  102. </div>
  103. </div>
  104. <div class="extra content" style="border-top: none !important">
  105. <div style="display: flex; align-items: center">
  106. <a
  107. :href="'/' + item.Repo.OwnerName"
  108. :title="item.Repo.OwnerName"
  109. >
  110. <img
  111. class="ui avatar image"
  112. style="width: 22px; height: 22px"
  113. :src="'/user/avatar/' + item.Repo.OwnerName + '/-1'"
  114. />
  115. </a>
  116. <span
  117. style="
  118. color: #999999;
  119. font-size: 12px;
  120. margin-left: 0.5rem;
  121. "
  122. >{{ item.CreatedUnix | transformTimestamp }}</span
  123. >
  124. <span
  125. style="
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. margin: 0 1rem;
  130. "
  131. title="引用次数"
  132. >
  133. <i class="ri-link"></i>
  134. <span
  135. style="
  136. color: #101010;
  137. font-size: 12px;
  138. margin-left: 0.2rem;
  139. "
  140. >{{ item.UseCount }}</span
  141. >
  142. </span>
  143. <span
  144. style="display: flex; align-items: center; flex: 1"
  145. title="下载次数"
  146. >
  147. <i class="ri-download-line"></i>
  148. <span
  149. style="
  150. color: #101010;
  151. font-size: 12px;
  152. margin-left: 0.2rem;
  153. "
  154. >{{ item.DownloadTimes }}</span
  155. >
  156. </span>
  157. <button
  158. class="ui mini button"
  159. @click.stop="cancelReferData(item.ID)"
  160. >
  161. {{ i18n.disassociate }}
  162. </button>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. </template>
  171. <template v-else>
  172. <div class="ui container">
  173. <div class="ui mobile reversed stackable grid">
  174. <div class="row" style="justify-content: space-between">
  175. <div class="ui blue small menu compact selectcloudbrain">
  176. <a class="item" :href="`${repoLink}/datasets`">{{
  177. i18n.current_dataset
  178. }}</a>
  179. <a
  180. class="active item"
  181. :href="`${repoLink}/datasets/reference_datasets`"
  182. >{{ i18n.linked_datasets }}</a
  183. >
  184. </div>
  185. <button class="ui green button" @click="openDataset()">
  186. {{ i18n.linked_datasets }}
  187. </button>
  188. </div>
  189. </div>
  190. <div class="ui placeholder segment bgtask-none">
  191. <div class="ui icon header bgtask-header-pic"></div>
  192. <div class="bgtask-content-header">还未关联过数据集</div>
  193. <div class="bgtask-content">
  194. <div class="bgtask-content-txt">
  195. 您可以通过单击新建关联数据集按钮,将平台上公开数据集展示在这里。
  196. </div>
  197. <div class="bgtask-content-txt">
  198. 使用说明可以参考启智AI协作平台<a
  199. href="https://git.openi.org.cn/zeizei/OpenI_Learning"
  200. >小白训练营课程</a
  201. >
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </template>
  207. <el-dialog
  208. :title="i18n.linked_datasets"
  209. :visible.sync="dialogVisible"
  210. :width="dialogWidth"
  211. >
  212. <div class="ui icon input dataset-search-vue">
  213. <i
  214. class="search icon"
  215. style="cursor: pointer; pointer-events: auto"
  216. @click="searchName"
  217. ></i>
  218. <input
  219. type="text"
  220. :placeholder="i18n.search_dataset"
  221. v-model="search"
  222. @keydown.enter.stop.prevent="searchName"
  223. />
  224. </div>
  225. <el-row>
  226. <el-col
  227. :span="17"
  228. style="
  229. padding-right: 1rem;
  230. border-right: 1px solid #f5f5f6;
  231. position: relative;
  232. "
  233. >
  234. <el-tabs v-model="activeName">
  235. <el-tab-pane :label="i18n.public_dataset" name="first">
  236. <el-row>
  237. <el-checkbox-group
  238. v-model="checkList"
  239. style="font-size: 14px; line-height: 1"
  240. >
  241. <div
  242. v-for="(item, index) in publicDatasetList"
  243. :key="index"
  244. class="select-data-wrap"
  245. >
  246. <div class="dataset-header-vue">
  247. <el-checkbox
  248. :label="item.ID"
  249. @change="(checked) => changeCheckbox(checked, item)"
  250. :title="item.Title"
  251. class="select-data-title"
  252. ><span class="ref-data-title">
  253. {{ item.Title }}
  254. </span></el-checkbox
  255. >
  256. <a
  257. class="select-data-title select-data-href"
  258. :href="`/${item.Repo.OwnerName}/${item.Repo.Name}/datasets`"
  259. :title="`${item.Repo.OwnerName}/${item.Repo.Alias}`"
  260. style="font-size: 12px"
  261. >{{ item.Repo.OwnerName }}/{{ item.Repo.Alias }}</a
  262. >
  263. </div>
  264. <div class="data-multiple-wrap" :title="item.Description">
  265. {{ item.Description }}
  266. </div>
  267. </div>
  268. </el-checkbox-group>
  269. </el-row>
  270. <div
  271. class="ui container"
  272. style="margin-top: 25px; text-align: center"
  273. >
  274. <el-pagination
  275. background
  276. @current-change="currentChange"
  277. :current-page="currentPage"
  278. :page-size="5"
  279. layout="total, prev, pager, next"
  280. :total="totalNum"
  281. >
  282. </el-pagination>
  283. </div>
  284. </el-tab-pane>
  285. </el-tabs>
  286. </el-col>
  287. <el-col
  288. :span="7"
  289. style="
  290. display: flex;
  291. flex-direction: column;
  292. height: 100%;
  293. right: 0;
  294. position: absolute;
  295. padding: 0 1.5rem;
  296. "
  297. >
  298. <div
  299. style="
  300. font-size: 14px;
  301. height: 40px;
  302. text-align: left;
  303. color: #0066ff;
  304. line-height: 40px;
  305. "
  306. >
  307. {{ i18n.selected_data_file }}
  308. </div>
  309. <div style="flex: 1; margin-top: 1.5rem">
  310. <el-checkbox-group v-model="checkList">
  311. <el-checkbox
  312. v-for="(item, index) in selectDatasetArray"
  313. :key="index"
  314. :label="item.ID"
  315. :title="item.Title"
  316. @change="(checked) => changeCheckSelected(checked, item)"
  317. style="display: flex; margin: 0.5rem 0"
  318. ><span class="select-data-right">{{
  319. item.Title
  320. }}</span></el-checkbox
  321. >
  322. </el-checkbox-group>
  323. </div>
  324. <div style="text-align: end">
  325. <el-button
  326. @click.native="confirmDataset"
  327. size="small"
  328. style="
  329. background: #389e0d;
  330. color: #fff;
  331. border: 1px solid #389e0d;
  332. "
  333. >{{ i18n.sure }}</el-button
  334. >
  335. </div>
  336. </el-col>
  337. </el-row>
  338. </el-dialog>
  339. </div>
  340. </template>
  341. <script>
  342. const { _AppSubUrl, _StaticUrlPrefix, csrf } = window.config;
  343. export default {
  344. components: {},
  345. data() {
  346. return {
  347. dialogWidth: "65%",
  348. dialogVisible: false,
  349. activeName: "first",
  350. repoLink: "",
  351. datasetList: [],
  352. test: false,
  353. checkList: [],
  354. publicDatasetList: [],
  355. showFlag: true,
  356. search: "",
  357. selectDatasetArray: [],
  358. paramsPublics: { page: 1, q: "" },
  359. i18n: {},
  360. totalNum: 0,
  361. currentPage: 1,
  362. };
  363. },
  364. methods: {
  365. openDataset() {
  366. console.log("open");
  367. this.dialogVisible = true;
  368. this.getDatasetList();
  369. },
  370. gotoDataset(item) {
  371. console.log(item);
  372. location.href = `/${item.Repo.OwnerName}/${item.Repo.Name}/datasets`;
  373. },
  374. currentChange(page) {
  375. this.paramsPublics.page = page;
  376. this.getDatasetList();
  377. },
  378. searchName() {
  379. this.paramsPublics.q = this.search;
  380. this.paramsPublics.page = 1;
  381. this.getDatasetList();
  382. },
  383. cancelReferData(id) {
  384. let url = `${this.repoLink}/datasets/reference_datasets/${id}`;
  385. this.$axios.delete(url).then((res) => {
  386. console.log(res);
  387. if (res.data.Code === 0) {
  388. console.log("delete success");
  389. let index = this.datasetList.find((item) => {
  390. return item.ID === id;
  391. });
  392. this.datasetList.splice(index, 1);
  393. }
  394. });
  395. },
  396. confirmDataset() {
  397. this.submitReferDataset();
  398. this.dialogVisible = false;
  399. },
  400. changeCheckbox(checked, item) {
  401. console.log(checked, item, this.checkList);
  402. if (checked) {
  403. this.selectDatasetArray.push({ ID: item.ID, Title: item.Title });
  404. } else {
  405. let index = this.selectDatasetArray.findIndex((element) => {
  406. return element.ID === item.ID;
  407. });
  408. this.selectDatasetArray.splice(index, 1);
  409. }
  410. console.log(this.selectDatasetArray);
  411. },
  412. changeCheckSelected(checked, item) {
  413. console.log(checked, item);
  414. if (!checked) {
  415. let index = this.selectDatasetArray.findIndex((element) => {
  416. return element.ID === item.ID;
  417. });
  418. this.selectDatasetArray.splice(index, 1);
  419. }
  420. console.log(this.checkList, this.selectDatasetArray);
  421. },
  422. postStar(item) {
  423. console.log(item);
  424. if (item.IsStaring) {
  425. let url = `${this.repoLink}/datasets/${item.ID}/unstar`;
  426. this.$axios.put(url).then((res) => {
  427. if (res.data.Code === 0) {
  428. this.datasetList.forEach((element, i) => {
  429. if (element.ID === item.ID) {
  430. this.datasetList[i].NumStars -= 1;
  431. this.datasetList[i].IsStaring = !this.datasetList[i].IsStaring;
  432. }
  433. });
  434. }
  435. });
  436. } else {
  437. let url = `${this.repoLink}/datasets/${item.ID}/star`;
  438. this.$axios.put(url).then((res) => {
  439. if (res.data.Code === 0) {
  440. this.datasetList.forEach((element, i) => {
  441. if (element.ID === item.ID) {
  442. this.datasetList[i].NumStars += 1;
  443. this.datasetList[i].IsStaring = !this.datasetList[i].IsStaring;
  444. }
  445. });
  446. }
  447. });
  448. }
  449. },
  450. getSelectDatasetList() {
  451. let url = `${this.repoLink}/datasets/reference_datasets_data`;
  452. this.$axios.get(url).then((res) => {
  453. this.datasetList = res.data;
  454. this.datasetList.length
  455. ? (this.showFlag = true)
  456. : (this.showFlag = false);
  457. console.log("this.getDatasetList:", this.datasetList);
  458. });
  459. },
  460. getDatasetList() {
  461. let url = `${this.repoLink}/datasets/reference_datasets_available`;
  462. this.$axios
  463. .get(url, {
  464. params: this.paramsPublics,
  465. })
  466. .then((res) => {
  467. this.publicDatasetList = JSON.parse(res.data.data);
  468. this.totalNum = parseInt(res.data.count);
  469. // this.search = "";
  470. // this.searchName();
  471. });
  472. },
  473. submitReferDataset() {
  474. let url = `${this.repoLink}/datasets/reference_datasets`;
  475. let data = this.qs.stringify({
  476. _csrf: csrf,
  477. dataset_id: this.checkList,
  478. });
  479. this.$axios.post(url, data).then((res) => {
  480. if (res.data.Code === 0) {
  481. this.getSelectDatasetList();
  482. }
  483. });
  484. },
  485. },
  486. filters: {
  487. transformTimestamp(timestamp) {
  488. const date = new Date(parseInt(timestamp) * 1000);
  489. const Y = date.getFullYear() + "-";
  490. const M =
  491. (date.getMonth() + 1 < 10
  492. ? "0" + (date.getMonth() + 1)
  493. : date.getMonth() + 1) + "-";
  494. const D =
  495. (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  496. const dateString = Y + M + D;
  497. return dateString;
  498. },
  499. },
  500. watch: {
  501. search(val) {
  502. if (!val) {
  503. this.searchName();
  504. }
  505. },
  506. },
  507. mounted() {
  508. this.getSelectDatasetList();
  509. },
  510. created() {
  511. this.repoLink = $(".reference-dataset").data("repolink") || "";
  512. if (document.documentElement.attributes["lang"].nodeValue == "en-US") {
  513. this.i18n = this.$locale.US;
  514. } else {
  515. this.i18n = this.$locale.CN;
  516. }
  517. },
  518. beforeDestroy() {},
  519. };
  520. </script>
  521. <style scoped>
  522. .dataset-search-vue {
  523. z-index: 9999;
  524. position: absolute;
  525. right: 31%;
  526. height: 30px;
  527. top: 60px;
  528. }
  529. .refer-dataset-card {
  530. cursor: pointer;
  531. box-shadow: 0px 4px 4px 0px rgba(232, 232, 232, 0.6);
  532. border: 1px solid rgba(232, 232, 232, 1);
  533. }
  534. .refer-dataset-card .refer-dataset-card-content {
  535. font-size: 16px;
  536. color: #0366d6;
  537. font-family: SourceHanSansSC-medium;
  538. height: 34px;
  539. font-weight: bold;
  540. display: flex;
  541. align-items: center;
  542. justify-content: space-between;
  543. }
  544. .refer-dataset-card-title {
  545. display: flex;
  546. align-items: center;
  547. max-width: 80%;
  548. width: 100%;
  549. }
  550. .dataset-card-flavor {
  551. display: flex;
  552. align-items: center;
  553. padding: 0.3rem 0.5rem;
  554. border: #888888;
  555. border-top-right-radius: 0 !important;
  556. border-bottom-right-radius: 0 !important;
  557. margin-right: -1px;
  558. }
  559. .card-flavor-num {
  560. padding: 0.5rem;
  561. border: #888888;
  562. border-top-left-radius: 0 !important;
  563. border-bottom-left-radius: 0 !important;
  564. cursor: default !important;
  565. }
  566. .card-flavor-desc {
  567. -webkit-box-orient: vertical;
  568. -webkit-line-clamp: 2;
  569. display: -webkit-box;
  570. overflow: hidden;
  571. color: #999999;
  572. font-size: 14px;
  573. margin-top: 10px;
  574. }
  575. .select-data-wrap {
  576. padding: 1rem 0;
  577. border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  578. }
  579. .select-data-title {
  580. flex: 1;
  581. overflow: hidden;
  582. }
  583. .select-data-title .ref-data-title {
  584. font-size: 18px;
  585. color: #454545;
  586. font-weight: 700;
  587. overflow: hidden;
  588. text-overflow: ellipsis;
  589. }
  590. .select-data-href {
  591. text-align: right;
  592. text-overflow: ellipsis;
  593. max-width: 35%;
  594. word-break: initial;
  595. margin-left: 1rem;
  596. }
  597. /deep/ .el-checkbox-group .el-checkbox .el-checkbox__label {
  598. max-width: 100%;
  599. }
  600. .select-data-right {
  601. overflow: hidden;
  602. vertical-align: middle;
  603. text-overflow: ellipsis;
  604. max-width: 100%;
  605. display: inline-block;
  606. }
  607. .data-multiple-wrap {
  608. -webkit-line-clamp: 3;
  609. -webkit-box-orient: vertical;
  610. display: -webkit-box;
  611. max-width: 100%;
  612. overflow: hidden;
  613. padding-top: 1rem;
  614. color: #888888;
  615. font: 12px;
  616. line-height: 20px;
  617. margin-left: 2rem;
  618. }
  619. </style>