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 22 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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, item.Title)"
  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. @closed="refreshData"
  217. >
  218. <div class="ui icon input dataset-search-vue">
  219. <i
  220. class="search icon"
  221. style="cursor: pointer; pointer-events: auto"
  222. @click="searchName"
  223. ></i>
  224. <input
  225. type="text"
  226. :placeholder="i18n.search_dataset"
  227. v-model="search"
  228. @keydown.enter.stop.prevent="searchName"
  229. />
  230. </div>
  231. <el-row>
  232. <el-col
  233. :span="17"
  234. style="
  235. padding-right: 1rem;
  236. border-right: 1px solid #f5f5f6;
  237. position: relative;
  238. "
  239. >
  240. <el-tabs v-model="activeName">
  241. <el-tab-pane :label="i18n.public_dataset" name="first">
  242. <el-row v-loading="loadingPublicPage">
  243. <el-checkbox-group
  244. v-model="checkList"
  245. style="font-size: 14px; line-height: 1"
  246. >
  247. <div
  248. v-for="(item, index) in publicDatasetList"
  249. :key="index"
  250. class="select-data-wrap"
  251. >
  252. <div class="dataset-header-vue">
  253. <el-checkbox
  254. :label="item.ID"
  255. @change="(checked) => changeCheckbox(checked, item)"
  256. :title="item.Title"
  257. class="select-data-title"
  258. style="display: flex; align-items: end"
  259. ><span class="ref-data-title">
  260. {{ item.Title }}
  261. </span></el-checkbox
  262. >
  263. <a
  264. class="select-data-title select-data-href"
  265. :href="`/${item.Repo.OwnerName}/${item.Repo.Name}/datasets`"
  266. :title="`${item.Repo.OwnerName}/${item.Repo.Alias}`"
  267. style="font-size: 12px"
  268. >{{ item.Repo.OwnerName }}/{{ item.Repo.Alias }}</a
  269. >
  270. </div>
  271. <div class="data-multiple-wrap" :title="item.Description">
  272. {{ item.Description }}
  273. </div>
  274. </div>
  275. </el-checkbox-group>
  276. </el-row>
  277. <div
  278. class="ui container"
  279. style="margin-top: 25px; text-align: center"
  280. >
  281. <el-pagination
  282. background
  283. @current-change="currentChange"
  284. :current-page="currentPage"
  285. :page-size="5"
  286. layout="total, prev, pager, next"
  287. :total="totalNum"
  288. >
  289. </el-pagination>
  290. </div>
  291. </el-tab-pane>
  292. </el-tabs>
  293. </el-col>
  294. <el-col
  295. :span="7"
  296. style="
  297. display: flex;
  298. flex-direction: column;
  299. height: 100%;
  300. right: 0;
  301. position: absolute;
  302. padding: 0 1.5rem;
  303. "
  304. >
  305. <div
  306. style="
  307. font-size: 14px;
  308. height: 40px;
  309. text-align: left;
  310. color: #0066ff;
  311. line-height: 40px;
  312. "
  313. >
  314. {{ i18n.selected_data_file }}
  315. </div>
  316. <div
  317. style="
  318. flex: 1;
  319. margin-top: 1.5rem;
  320. margin-bottom: 1rem;
  321. overflow-y: auto;
  322. "
  323. >
  324. <el-checkbox-group v-model="checkList">
  325. <el-checkbox
  326. v-for="(item, index) in selectDatasetArray"
  327. :key="index"
  328. :label="item.ID"
  329. :title="item.Title"
  330. @change="(checked) => changeCheckSelected(checked, item)"
  331. style="display: flex; margin: 0.5rem 0"
  332. ><span class="select-data-right">{{
  333. item.Title
  334. }}</span></el-checkbox
  335. >
  336. </el-checkbox-group>
  337. </div>
  338. <div style="text-align: end">
  339. <el-button
  340. @click.native="confirmDataset"
  341. size="small"
  342. style="
  343. background: #389e0d;
  344. color: #fff;
  345. border: 1px solid #389e0d;
  346. "
  347. >{{ i18n.sure }}</el-button
  348. >
  349. </div>
  350. </el-col>
  351. </el-row>
  352. </el-dialog>
  353. </div>
  354. </template>
  355. <script>
  356. const { _AppSubUrl, _StaticUrlPrefix, csrf } = window.config;
  357. export default {
  358. components: {},
  359. data() {
  360. return {
  361. dialogWidth: "65%",
  362. dialogVisible: false,
  363. activeName: "first",
  364. repoLink: "",
  365. datasetList: [],
  366. test: false,
  367. checkList: [],
  368. publicDatasetList: [],
  369. showFlag: true,
  370. search: "",
  371. selectDatasetArray: [],
  372. paramsPublics: { page: 1, q: "" },
  373. i18n: {},
  374. totalNum: 0,
  375. currentPage: 1,
  376. loadingLinkPage: false,
  377. loadingPublicPage: false,
  378. };
  379. },
  380. methods: {
  381. openDataset() {
  382. this.checkList = this.datasetList.map((item) => {
  383. this.selectDatasetArray.push({ ID: item.ID, Title: item.Title });
  384. return item.ID;
  385. });
  386. console.log("open");
  387. this.dialogVisible = true;
  388. this.getDatasetList();
  389. },
  390. refreshData() {
  391. this.checkList = [];
  392. this.selectDatasetArray = [];
  393. },
  394. gotoDataset(item) {
  395. console.log(item);
  396. location.href = `/${item.Repo.OwnerName}/${item.Repo.Name}/datasets`;
  397. },
  398. currentChange(page) {
  399. this.paramsPublics.page = page;
  400. this.getDatasetList();
  401. },
  402. searchName() {
  403. this.paramsPublics.q = this.search;
  404. this.paramsPublics.page = 1;
  405. this.getDatasetList();
  406. },
  407. cancelReferData(id, name) {
  408. let url = `${this.repoLink}/datasets/reference_datasets/${id}`;
  409. this.$axios
  410. .delete(url)
  411. .then((res) => {
  412. console.log(res);
  413. if (res.data.Code === 0) {
  414. console.log("delete success");
  415. this.$message.success(`取消${name}关联数据集成功!`);
  416. let index = this.datasetList.findIndex((item) => {
  417. return item.ID === id;
  418. });
  419. this.datasetList.splice(index, 1);
  420. } else {
  421. this.$message.error(`取消关联数据集失败!`);
  422. }
  423. })
  424. .catch((err) => {
  425. this.$message.error(`取消关联数据集失败!`);
  426. console.log(err);
  427. });
  428. },
  429. confirmDataset() {
  430. this.submitReferDataset();
  431. this.dialogVisible = false;
  432. },
  433. changeCheckbox(checked, item) {
  434. console.log(checked, item, this.checkList);
  435. if (checked) {
  436. this.selectDatasetArray.push({ ID: item.ID, Title: item.Title });
  437. } else {
  438. let index = this.selectDatasetArray.findIndex((element) => {
  439. return element.ID === item.ID;
  440. });
  441. this.selectDatasetArray.splice(index, 1);
  442. }
  443. console.log(this.selectDatasetArray);
  444. },
  445. changeCheckSelected(checked, item) {
  446. console.log(checked, item);
  447. if (!checked) {
  448. let index = this.selectDatasetArray.findIndex((element) => {
  449. return element.ID === item.ID;
  450. });
  451. this.selectDatasetArray.splice(index, 1);
  452. }
  453. console.log(this.checkList, this.selectDatasetArray);
  454. },
  455. postStar(item) {
  456. console.log(item);
  457. if (item.IsStaring) {
  458. let url = `${this.repoLink}/datasets/${item.ID}/unstar`;
  459. this.$axios.put(url).then((res) => {
  460. if (res.data.Code === 0) {
  461. this.datasetList.forEach((element, i) => {
  462. if (element.ID === item.ID) {
  463. this.datasetList[i].NumStars -= 1;
  464. this.datasetList[i].IsStaring = !this.datasetList[i].IsStaring;
  465. }
  466. });
  467. }
  468. });
  469. } else {
  470. let url = `${this.repoLink}/datasets/${item.ID}/star`;
  471. this.$axios.put(url).then((res) => {
  472. if (res.data.Code === 0) {
  473. this.datasetList.forEach((element, i) => {
  474. if (element.ID === item.ID) {
  475. this.datasetList[i].NumStars += 1;
  476. this.datasetList[i].IsStaring = !this.datasetList[i].IsStaring;
  477. }
  478. });
  479. }
  480. });
  481. }
  482. },
  483. getSelectDatasetList() {
  484. this.loadingLinkPage = true;
  485. let url = `${this.repoLink}/datasets/reference_datasets_data`;
  486. this.$axios.get(url).then((res) => {
  487. this.loadingLinkPage = false;
  488. console.log(res);
  489. if (!res.data) {
  490. this.showFlag = false;
  491. return;
  492. } else {
  493. this.datasetList = res.data;
  494. this.datasetList.length
  495. ? (this.showFlag = true)
  496. : (this.showFlag = false);
  497. }
  498. console.log("this.getDatasetList:", this.datasetList, this.checkList);
  499. });
  500. },
  501. getDatasetList() {
  502. this.loadingPublicPage = true;
  503. let url = `${this.repoLink}/datasets/reference_datasets_available`;
  504. this.$axios
  505. .get(url, {
  506. params: this.paramsPublics,
  507. })
  508. .then((res) => {
  509. this.publicDatasetList = JSON.parse(res.data.data);
  510. this.totalNum = parseInt(res.data.count);
  511. this.loadingPublicPage = false;
  512. });
  513. },
  514. submitReferDataset() {
  515. let url = `${this.repoLink}/datasets/reference_datasets`;
  516. let data = this.qs.stringify(
  517. {
  518. _csrf: csrf,
  519. dataset_id: this.checkList,
  520. },
  521. { arrayFormat: "repeat" }
  522. );
  523. console.log(data);
  524. this.$axios
  525. .post(url, data)
  526. .then((res) => {
  527. if (res.data.Code === 0) {
  528. this.$message.success(`关联数据集成功!`);
  529. this.getSelectDatasetList();
  530. } else {
  531. this.$message.error(`关联数据集失败!`);
  532. }
  533. })
  534. .catch((err) => {
  535. this.$message.error(`关联数据集失败!`);
  536. console.log(err);
  537. });
  538. },
  539. },
  540. filters: {
  541. transformTimestamp(timestamp) {
  542. const date = new Date(parseInt(timestamp) * 1000);
  543. const Y = date.getFullYear() + "-";
  544. const M =
  545. (date.getMonth() + 1 < 10
  546. ? "0" + (date.getMonth() + 1)
  547. : date.getMonth() + 1) + "-";
  548. const D =
  549. (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  550. const dateString = Y + M + D;
  551. return dateString;
  552. },
  553. },
  554. watch: {
  555. search(val) {
  556. if (!val) {
  557. this.searchName();
  558. }
  559. },
  560. },
  561. mounted() {
  562. this.getSelectDatasetList();
  563. },
  564. created() {
  565. this.repoLink = $(".reference-dataset").data("repolink") || "";
  566. if (document.documentElement.attributes["lang"].nodeValue == "en-US") {
  567. this.i18n = this.$locale.US;
  568. } else {
  569. this.i18n = this.$locale.CN;
  570. }
  571. },
  572. beforeDestroy() {},
  573. };
  574. </script>
  575. <style scoped>
  576. .dataset-search-vue {
  577. z-index: 9999;
  578. position: absolute;
  579. right: 31%;
  580. height: 30px;
  581. top: 60px;
  582. }
  583. .refer-dataset-card {
  584. cursor: pointer;
  585. box-shadow: 0px 4px 4px 0px rgba(232, 232, 232, 0.6);
  586. border: 1px solid rgba(232, 232, 232, 1);
  587. }
  588. .refer-dataset-card .refer-dataset-card-content {
  589. font-size: 16px;
  590. color: #0366d6;
  591. font-family: SourceHanSansSC-medium;
  592. height: 34px;
  593. font-weight: bold;
  594. display: flex;
  595. align-items: center;
  596. justify-content: space-between;
  597. }
  598. .refer-dataset-card-title {
  599. display: flex;
  600. align-items: center;
  601. max-width: 80%;
  602. width: 100%;
  603. }
  604. .dataset-card-flavor {
  605. display: flex;
  606. align-items: center;
  607. padding: 0.3rem 0.5rem;
  608. border: #888888;
  609. border-top-right-radius: 0 !important;
  610. border-bottom-right-radius: 0 !important;
  611. margin-right: -1px;
  612. }
  613. .card-flavor-num {
  614. padding: 0.5rem;
  615. border: #888888;
  616. border-top-left-radius: 0 !important;
  617. border-bottom-left-radius: 0 !important;
  618. cursor: default !important;
  619. }
  620. .card-flavor-desc {
  621. -webkit-box-orient: vertical;
  622. -webkit-line-clamp: 2;
  623. display: -webkit-box;
  624. overflow: hidden;
  625. color: #999999;
  626. font-size: 14px;
  627. margin-top: 10px;
  628. }
  629. .select-data-wrap {
  630. padding: 1rem 0;
  631. border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  632. }
  633. .select-data-title {
  634. flex: 1;
  635. overflow: hidden;
  636. }
  637. .select-data-title .ref-data-title {
  638. font-size: 18px;
  639. color: #454545;
  640. font-weight: 700;
  641. overflow: hidden;
  642. text-overflow: ellipsis;
  643. }
  644. .select-data-href {
  645. text-align: right;
  646. text-overflow: ellipsis;
  647. max-width: 35%;
  648. word-break: initial;
  649. margin-left: 1rem;
  650. }
  651. /deep/ .el-checkbox-group .el-checkbox .el-checkbox__label {
  652. display: flex;
  653. max-width: 90%;
  654. }
  655. .select-data-right {
  656. overflow: hidden;
  657. vertical-align: middle;
  658. text-overflow: ellipsis;
  659. max-width: 100%;
  660. display: inline-block;
  661. }
  662. .data-multiple-wrap {
  663. -webkit-line-clamp: 3;
  664. -webkit-box-orient: vertical;
  665. display: -webkit-box;
  666. max-width: 100%;
  667. overflow: hidden;
  668. padding-top: 1rem;
  669. color: #888888;
  670. font: 12px;
  671. line-height: 20px;
  672. margin-left: 2rem;
  673. }
  674. </style>