ProjectModal.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <t-dialog
  3. v-model:visible="props.visible"
  4. :header="title[props.type]"
  5. class="project-dialog"
  6. :width="700"
  7. @close="close"
  8. @confirm="confirm"
  9. >
  10. <div class="flex box-list" style="flex-wrap:wrap;justify-content: flex-start;">
  11. <template v-if="replaceDialog.list?.length">
  12. <div class="box" :class="{active:replaceDialog.select?.id===_item.id}" @click="selectScene(_item)" v-for="_item in replaceDialog.list">
  13. <div class="box-img">
  14. <img :src="_item.image"></img>
  15. </div>
  16. <div class="item-title" :title="_item.name">{{_item.name}}</div>
  17. </div>
  18. </template>
  19. <template v-else >
  20. <div class="item-title" style="height:50px;">
  21. {{$t('暂无数据')}}
  22. </div>
  23. </template>
  24. </div>
  25. <t-pagination :pageSizeOptions="[15,30,60]" :total="replaceDialog.total" v-model="replaceDialog.current" :pageSize="replaceDialog.pageSize" @change="pageChange" />
  26. </t-dialog>
  27. </template>
  28. <script lang='ts' setup>
  29. import { reactive,defineComponent,ref, onMounted, watch } from 'vue';
  30. import { getCollectionList } from '@/services/api';
  31. const props = defineProps<{
  32. visible: boolean;
  33. type: string;
  34. }>();
  35. const emit = defineEmits(['update:visible', 'change']);
  36. function close() {
  37. emit('update:visible', false);
  38. }
  39. const replaceDialog = reactive<any>({
  40. list:[],
  41. current:1,
  42. pageSize:15,
  43. total:0,
  44. collection:'v',
  45. select:{
  46. }
  47. });
  48. const title = {
  49. template:'模版列表',
  50. c:'选择组件'
  51. }
  52. watch(()=>props.visible,(val)=>{
  53. if(val){
  54. getList(props.type);
  55. }
  56. })
  57. const getList = async(e?:string) => {
  58. let collection = e;
  59. if(!collection){
  60. collection = replaceDialog.collection;
  61. }else{
  62. replaceDialog.collection = e;
  63. replaceDialog.current = 1;
  64. }
  65. const data = {
  66. template:false,
  67. projection: 'name,image,id',
  68. };
  69. if(collection === 'template'){
  70. collection = 'v';
  71. data.template = true;
  72. }
  73. const config = {
  74. params: {
  75. current: replaceDialog.current,
  76. pageSize: replaceDialog.pageSize,
  77. },
  78. };
  79. //2.请求所有图纸/组件数据
  80. const res: any = await getCollectionList(collection, data, config);
  81. replaceDialog.list = res.list;
  82. replaceDialog.total = res.total;
  83. }
  84. const pageChange = (e) => {
  85. replaceDialog.current = e.current;
  86. replaceDialog.pageSize = e.pageSize;
  87. getList();
  88. }
  89. const confirm = () => {
  90. emit('change',replaceDialog.select);
  91. }
  92. const selectScene = (_item) => {
  93. replaceDialog.select = _item;
  94. }
  95. </script>
  96. <style lang='postcss' scoped>
  97. .box-list{
  98. flex-wrap: wrap;
  99. padding:8px;
  100. margin-bottom:12px;
  101. background-color: var(--color-background-active);
  102. overflow:scroll;
  103. max-height:375px;
  104. min-height: 350px;
  105. .box{
  106. width:125px;
  107. height:110px;
  108. padding:8px;
  109. .box-img{
  110. width:100%;
  111. height:70px;
  112. }
  113. /* .title{
  114. text-align:center;
  115. white-space: nowrap;
  116. overflow: hidden;
  117. text-overflow:ellipsis;
  118. font-size:12px;
  119. color: var(--td-text-color-secondary);
  120. } */
  121. &:hover{
  122. border-radius: 4px;
  123. border:1px solid var(--color-primary);
  124. }
  125. }
  126. .item-title{
  127. text-align:center;
  128. white-space: nowrap;
  129. overflow: hidden;
  130. text-overflow:ellipsis;
  131. font-size:12px;
  132. color: var(--td-text-color-secondary);
  133. }
  134. .active{
  135. border-radius: 4px;
  136. border:1px solid var(--color-primary);
  137. }
  138. }
  139. </style>