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