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