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