tableSelect2.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <div class="table-select">
  3. <span class="title">{{title}}</span>
  4. <div class="close-btn"><i class="iconfont icon-pop-ups_shut-down" @click="$emit('cancle')"></i></div>
  5. <div class="material-tab">
  6. <a class="material-tab-item" @click.prevent="currentMaterialType = 'image'">
  7. <span class="text">图片</span>
  8. <div v-if="currentMaterialType === 'image'" class="bottom-line"></div>
  9. </a>
  10. <a class="material-tab-item" @click.prevent="currentMaterialType = 'pano'">
  11. <span class="text">全景图</span>
  12. <div v-if="currentMaterialType === 'pano'" class="bottom-line"></div>
  13. </a>
  14. <a class="material-tab-item" @click.prevent="currentMaterialType = '3D'">
  15. <span class="text">三维场景</span>
  16. <div v-if="currentMaterialType === '3D'" class="bottom-line"></div>
  17. </a>
  18. </div>
  19. <div class="filter">
  20. <input type="text" placeholder="输入关键词" v-model="searchKey"/>
  21. <i v-if="!searchKey" class="iconfont icon-editor_search search-icon"/>
  22. <i v-if="searchKey" @click="searchKey=''" class="iconfont icontoast_red clear-icon"></i>
  23. </div>
  24. <div class="table" v-show="currentMaterialType === 'image'">
  25. <div class="table-head-row">
  26. <span class="table-head">1</span>
  27. <span class="table-head" v-for="(item,i) in tableHeadersForImage" :key="i">{{item.name}}</span>
  28. </div>
  29. <div
  30. class="table-body"
  31. v-infinite-scroll="requestMoreImageData"
  32. :infinite-scroll-disabled="!hasMoreImageData || isRequestingMoreImageData"
  33. >
  34. <div class="table-body-row" v-for="(item,i) in imageList" :key="i">
  35. <span class="table-data">
  36. <div class="checkbox">
  37. <!-- 负责功能 -->
  38. <input
  39. type="checkbox"
  40. @change="e => selectItem(item, e.target)"
  41. :checked="select.some(i => i[primaryKey] === item[primaryKey])"
  42. >
  43. <!-- 负责外观 -->
  44. <span class="for-outer-circle"></span>
  45. <span class="for-inner-circle"></span>
  46. </div>
  47. </span>
  48. <span class="table-data" v-for="(sub,idx) in tableHeadersForImage" :key="idx">
  49. <div v-if="sub.type=='image'" class="list-img">
  50. <img :src="item[sub.key] + `?x-oss-process=image/resize,p_10&${Math.random()}`" alt="">
  51. </div>
  52. <span class="ellipsis" v-else v-title="sub.key === 'name' ? item[sub.key] : ''">{{ item[sub.key] }}</span>
  53. </span>
  54. </div>
  55. </div>
  56. <!-- 无数据时的提示 -->
  57. <tbody v-if="imageList.length === 0 && !hasMoreImageData">
  58. <tr>
  59. <td colspan="10">
  60. <div class="nodata">
  61. <img :src="$noresult" alt="">
  62. <span v-if="lastestUsedSearchKey">{{'未搜索到结果~'}}</span>
  63. <span v-if="!lastestUsedSearchKey">{{'暂无素材,快去上传吧'}}</span>
  64. </div>
  65. </td>
  66. </tr>
  67. </tbody>
  68. </div>
  69. <div class="table" v-show="currentMaterialType === 'pano'">
  70. <div class="table-head-row">
  71. <span class="table-head">1</span>
  72. <span class="table-head" v-for="(item,i) in tableHeadersForPano" :key="i">{{item.name}}</span>
  73. </div>
  74. <div
  75. class="table-body"
  76. v-infinite-scroll="requestMorePanoData"
  77. :infinite-scroll-disabled="!hasMorePanoData || isRequestingMorePanoData"
  78. >
  79. <div class="table-body-row" v-for="(item,i) in panoList" :key="i">
  80. <span class="table-data">
  81. <div class="checkbox">
  82. <!-- 负责功能 -->
  83. <input
  84. type="checkbox"
  85. @change="e => selectItem(item, e.target)"
  86. :checked="select.some(i => i[primaryKey] === item[primaryKey])"
  87. >
  88. <!-- 负责外观 -->
  89. <span class="for-outer-circle"></span>
  90. <span class="for-inner-circle"></span>
  91. </div>
  92. </span>
  93. <span class="table-data" v-for="(sub,idx) in tableHeadersForPano" :key="idx">
  94. <div v-if="sub.type=='image'" class="list-img">
  95. <img :src="item[sub.key] + `?x-oss-process=image/resize,p_10&${Math.random()}`" alt="">
  96. </div>
  97. <span class="ellipsis" v-else v-title="sub.key === 'name' ? item[sub.key] : ''">{{item[sub.key]}}</span>
  98. </span>
  99. </div>
  100. </div>
  101. <!-- 无数据时的提示 -->
  102. <tbody v-if="panoList.length === 0 && !hasMorePanoData">
  103. <tr>
  104. <td colspan="10">
  105. <div class="nodata">
  106. <img :src="$noresult" alt="">
  107. <span v-if="lastestUsedSearchKey">{{'未搜索到结果~'}}</span>
  108. <span v-if="!lastestUsedSearchKey">{{'暂无素材,快去上传吧'}}</span>
  109. </div>
  110. </td>
  111. </tr>
  112. </tbody>
  113. </div>
  114. <div class="btns">
  115. <a @click="$emit('cancle')">取消</a>
  116. <a :class="{disable: !select.length}" @click="$emit('submit', select)">确定</a>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import vAudio from '@/components/audio'
  122. import { getMaterialList} from "@/api";
  123. import { changeByteUnit } from '@/utils/file'
  124. import config from "@/config";
  125. import { debounce } from "@/utils/other.js"
  126. export default {
  127. props:{
  128. title:{
  129. default:'',
  130. type:String
  131. },
  132. primaryKey: {
  133. default:'id'
  134. },
  135. },
  136. components:{
  137. vAudio
  138. },
  139. watch:{
  140. searchKey: {
  141. handler: function () {
  142. this.refreshMaterialList(this.currentMaterialType)
  143. },
  144. immediate: false,
  145. },
  146. currentMaterialType: {
  147. handler: function (newVal) {
  148. if (newVal === 'image' && this.imageList.length === 0) {
  149. this.refreshMaterialList('image')
  150. } else if (newVal === 'pano' && this.panoList.length === 0) {
  151. this.refreshMaterialList('pano')
  152. }
  153. },
  154. immediate: false,
  155. }
  156. },
  157. computed:{
  158. tableHeadersForImage(){
  159. return this.$MAPTABLEHEADER['image'].filter(item=>{
  160. return ['icon', 'name', 'fileSize', 'dpi'].includes(item.key)
  161. })
  162. },
  163. tableHeadersForPano(){
  164. return this.$MAPTABLEHEADER['pano'].filter(item=>{
  165. return ['icon', 'name', 'fileSize'].includes(item.key)
  166. })
  167. },
  168. },
  169. data () {
  170. return {
  171. imageList: [],
  172. panoList: [],
  173. select: [],
  174. searchKey:'', // 搜索关键词
  175. lastestUsedSearchKey: '',
  176. currentMaterialType: 'image',
  177. isRequestingMoreImageData: false,
  178. isRequestingMorePanoData: false,
  179. hasMoreImageData: true,
  180. hasMorePanoData: true,
  181. }
  182. },
  183. methods: {
  184. selectItem(item, eventTarget) {
  185. if (item.isUse == '1') {
  186. eventTarget.checked = false
  187. return this.$alert({content:'选中素材不能超过600kb'})
  188. }
  189. this.select = [item]
  190. },
  191. requestMoreImageData() {
  192. this.isRequestingMoreImageData = true
  193. const lastestUsedSearchKey = this.searchKey
  194. getMaterialList(
  195. {
  196. pageNum: Math.floor(this.imageList.length / config.PAGE_SIZE) + 1,
  197. pageSize: config.PAGE_SIZE,
  198. searchKey: this.searchKey,
  199. type: 'image',
  200. },
  201. (data) => {
  202. const newData = data.data.list.map((i) => {
  203. i.isUse = i.fileSize > 600 ? '1' : '0'
  204. i.fileSize = changeByteUnit(Number(i.fileSize));
  205. i.createTime = i.createTime.substring(0, i.createTime.length - 3)
  206. i.updateTime = i.updateTime.substring(0, i.updateTime.length - 3)
  207. return i;
  208. });
  209. this.imageList = this.imageList.concat(newData)
  210. if (this.imageList.length === data.data.total) {
  211. this.hasMoreImageData = false
  212. }
  213. this.isRequestingMoreImageData = false
  214. this.lastestUsedSearchKey = lastestUsedSearchKey
  215. },
  216. () => {
  217. this.isRequestingMoreImageData = false
  218. this.lastestUsedSearchKey = lastestUsedSearchKey
  219. }
  220. );
  221. },
  222. requestMorePanoData() {
  223. this.isRequestingMorePanoData = true
  224. const lastestUsedSearchKey = this.searchKey
  225. getMaterialList(
  226. {
  227. pageNum: Math.floor(this.panoList.length / config.PAGE_SIZE) + 1,
  228. pageSize: config.PAGE_SIZE,
  229. searchKey: this.searchKey,
  230. type: 'pano',
  231. },
  232. (data) => {
  233. const newData = data.data.list.map((i) => {
  234. i.isUse = i.fileSize > 600 ? '1' : '0'
  235. i.fileSize = changeByteUnit(Number(i.fileSize));
  236. i.createTime = i.createTime.substring(0, i.createTime.length - 3)
  237. i.updateTime = i.updateTime.substring(0, i.updateTime.length - 3)
  238. return i;
  239. });
  240. this.panoList = this.panoList.concat(newData)
  241. if (this.panoList.length === data.data.total) {
  242. this.hasMorePanoeData = false
  243. }
  244. this.isRequestingMorePanoeData = false
  245. this.lastestUsedSearchKey = lastestUsedSearchKey
  246. },
  247. () => {
  248. this.isRequestingMorePanoeData = false
  249. this.lastestUsedSearchKey = lastestUsedSearchKey
  250. }
  251. );
  252. },
  253. refreshMaterialList: debounce(function(type) {
  254. if (type === 'image') {
  255. this.isRequestingMoreImageData = false
  256. this.hasMoreImageData = true
  257. this.imageList = []
  258. this.requestMoreImageData()
  259. } else if (type === 'pano') {
  260. this.isRequestingMorePanoData = false
  261. this.hasMorePanoData = true
  262. this.panoList = []
  263. this.requestMorePanoData()
  264. }
  265. }, 700, false),
  266. },
  267. mounted() {
  268. }
  269. }
  270. </script>
  271. <style lang="less" scoped>
  272. ::-webkit-scrollbar { width: 6px; height: 0; } /*宽度是对垂直滚动条而言,高度是对水平滚动条而言*/
  273. ::-webkit-scrollbar-thumb {
  274. background: #47484A;
  275. border-radius: 3px;
  276. }
  277. ::-webkit-scrollbar-button { background-color: none; height: 0; }
  278. ::-webkit-scrollbar-track { background: transparent; border-radius: 6px; }
  279. ::-webkit-scrollbar-corner { background: transparent; border-radius: 6px; }
  280. ::-webkit-scrollbar-resizer { background: transparent;}
  281. .ellipsis{
  282. text-overflow: ellipsis;
  283. overflow: hidden;
  284. white-space: nowrap;
  285. width: 100%;
  286. display: inline-block;
  287. }
  288. .table-select {
  289. position: absolute;
  290. z-index: 3;
  291. left: 50%;
  292. top: 50%;
  293. transform: translateX(-50%) translateY(-50%);
  294. width: 600px;
  295. height: 730px;
  296. background: #1A1B1D;
  297. border-radius: 4px;
  298. border: 1px solid #404040;
  299. padding: 26px;
  300. }
  301. .title {
  302. font-size: 18px;
  303. color: rgba(255, 255, 255, 0.6);
  304. }
  305. .close-btn {
  306. display: inline-block;
  307. position: absolute;
  308. top: 26px;
  309. right: 20px;
  310. font-size: 12px;
  311. color: #969799;
  312. cursor: pointer;
  313. padding: 6px;
  314. }
  315. .material-tab {
  316. margin-top: 35px;
  317. > .material-tab-item {
  318. display: inline-block;
  319. margin-right: 20px;
  320. position: relative;
  321. cursor: pointer;
  322. > .text {
  323. font-size: 14px;
  324. font-family: MicrosoftYaHei;
  325. color: rgba(255, 255, 255, 0.6);
  326. }
  327. > .bottom-line {
  328. position: absolute;
  329. left: 50%;
  330. transform: translateX(-50%);
  331. bottom: -4px;
  332. width: 16px;
  333. height: 2px;
  334. background: #0076F6;
  335. border-radius: 1px;
  336. }
  337. }
  338. }
  339. .filter {
  340. margin-top: 28px;
  341. width: 100%;
  342. height: 36px;
  343. background: #252526;
  344. border-radius: 2px;
  345. border: 1px solid #404040;
  346. position: relative;
  347. > input {
  348. box-sizing: border-box;
  349. width: calc(100% - 42px);
  350. height: 100%;
  351. border: none;
  352. padding-left: 16px;
  353. background: transparent;
  354. color: #fff;
  355. outline: none;
  356. }
  357. > .search-icon {
  358. position: absolute;
  359. top: 50%;
  360. transform: translateY(-50%);
  361. right: 18px;
  362. color: #404040;
  363. font-size: 20px;
  364. }
  365. > .clear-icon {
  366. position: absolute;
  367. top: 50%;
  368. transform: translateY(-50%);
  369. right: 18px;
  370. color: #404040;
  371. font-size: 20px;
  372. cursor: pointer;
  373. }
  374. }
  375. @table-height: 440px;
  376. @table-head-row-height: 40px;
  377. @table-border-size: 1px;
  378. .table {
  379. margin-top: 20px;
  380. border: @table-border-size solid #404040;
  381. background: #1A1B1D;
  382. width: 100%;
  383. height: @table-height;
  384. > .table-head-row {
  385. width: 100%;
  386. height: @table-head-row-height;
  387. background: #252526;
  388. color: rgba(255, 255, 255, 0.6);
  389. .table-head {
  390. font-size: 16px;
  391. line-height: @table-head-row-height;
  392. height: 100%;
  393. display: inline-block;
  394. &:nth-of-type(1) {
  395. width: 50px;
  396. color: transparent;
  397. }
  398. &:nth-of-type(2) {
  399. width: calc(116px - 50px);
  400. }
  401. &:nth-of-type(3) {
  402. width: calc(316px - 116px);
  403. }
  404. &:nth-of-type(4) {
  405. width: calc(416px - 316px);
  406. }
  407. &:nth-of-type(5) {
  408. width: calc(100% - 416px);
  409. }
  410. }
  411. }
  412. > .table-body {
  413. height: calc(@table-height - @table-head-row-height - @table-border-size - @table-border-size);
  414. overflow: auto;
  415. display: inline-block;
  416. width: 100%;
  417. > .table-body-row {
  418. height: 50px;
  419. border-bottom: 1px solid #404040;
  420. display: flex;
  421. align-items: center;
  422. &:last-of-type {
  423. border-bottom: none;
  424. }
  425. > .table-data {
  426. font-size:14px;
  427. line-height:50px;
  428. height: 100%;
  429. color: #fff;
  430. &:nth-of-type(1) {
  431. width: 50px;
  432. }
  433. &:nth-of-type(2) {
  434. width: calc(116px - 50px);
  435. }
  436. &:nth-of-type(3) {
  437. width: calc(316px - 116px);
  438. padding-right: 50px;
  439. }
  440. &:nth-of-type(4) {
  441. width: calc(416px - 316px);
  442. }
  443. &:nth-of-type(5) {
  444. width: calc(100% - 416px);
  445. }
  446. > .list-img {
  447. position: relative;
  448. height: 100%;
  449. display: inline-block;
  450. width: 100%;
  451. > img {
  452. position: absolute;
  453. top: 50%;
  454. transform: translateY(-50%);
  455. width: 40px;
  456. height: 40px;
  457. object-fit: cover;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. .checkbox {
  465. position: relative;
  466. width: 100%;
  467. height: 100%;
  468. input {
  469. width: 20px;
  470. height: 20px;
  471. position: absolute;
  472. left: 50%;
  473. top: 50%;
  474. transform: translate(-50%, -50%);
  475. opacity: 0;
  476. cursor: pointer;
  477. }
  478. .for-outer-circle {
  479. width: 16px;
  480. height: 16px;
  481. position: absolute;
  482. left: 50%;
  483. top: 50%;
  484. transform: translate(-50%, -50%);
  485. border-radius: 50%;
  486. border: 1px solid #404040;
  487. pointer-events: none;
  488. }
  489. .for-inner-circle {
  490. width: 8px;
  491. height: 8px;
  492. position: absolute;
  493. left: 50%;
  494. top: 50%;
  495. transform: translate(-50%, -50%);
  496. border-radius: 50%;
  497. background: #0076F6;
  498. pointer-events: none;
  499. opacity: 0;
  500. }
  501. }
  502. .checkbox > input:checked ~ .for-outer-circle {
  503. border: 1px solid #0076F6;
  504. }
  505. .checkbox > input:checked ~ .for-inner-circle {
  506. opacity: 1;
  507. }
  508. .checkbox > input:disabled {
  509. cursor: not-allowed;
  510. }
  511. // .checkbox > input:disabled + span {
  512. // }
  513. .btns {
  514. text-align: center;
  515. > a {
  516. width:120px;
  517. height:40px;
  518. text-align: center;
  519. line-height: 40px;
  520. opacity:1;
  521. border-radius:20px;
  522. font-size:12px;
  523. cursor: pointer;
  524. display: inline-block;
  525. color: @color;
  526. margin: 0 10px;
  527. &:nth-child(2) {
  528. background-color: @color;
  529. color: #fff;
  530. }
  531. &:nth-child(1) {
  532. border:1px solid @color;
  533. }
  534. }
  535. .disable{
  536. pointer-events: none!important;
  537. opacity: 0.5!important;
  538. }
  539. }
  540. </style>