index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div
  3. v-loading="loading || innerLoading"
  4. class="template-list-wrap"
  5. >
  6. <div
  7. v-if="hasCreate"
  8. class="template-item"
  9. @click="addNew"
  10. >
  11. <div
  12. class="iconfont-div"
  13. >
  14. <i class="iconfont el-icon-plus" />
  15. </div>
  16. <div
  17. class="name"
  18. >
  19. 从空白新建
  20. </div>
  21. </div>
  22. <div
  23. v-for="template in templateList"
  24. :key="template.id"
  25. class="template-item template-choose-item"
  26. >
  27. <div
  28. class="thumbnail"
  29. >
  30. <el-image
  31. :ref="'img' + template.id"
  32. :src="template.thumbnail"
  33. :preview-src-list="[template.thumbnail]"
  34. />
  35. <span class="template-list-item-actions">
  36. <i
  37. class="el-icon-zoom-in"
  38. @click="preview(template.id)"
  39. />
  40. <i
  41. class="el-icon-edit-outline"
  42. @click="useIt(template.id)"
  43. />
  44. </span>
  45. </div>
  46. <div class="name">
  47. {{ template.name }}
  48. </div>
  49. </div>
  50. <el-empty
  51. v-if="!templateList.length && !hasCreate"
  52. description="暂无模板"
  53. />
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. name: 'TemplateList',
  59. model: {
  60. prop: 'value',
  61. event: 'change'
  62. },
  63. props: {
  64. loading: {
  65. type: Boolean,
  66. default: false
  67. },
  68. hasCreate: {
  69. type: Boolean,
  70. default: false
  71. },
  72. value: {
  73. type: String,
  74. default: ''
  75. },
  76. pageInfo: {
  77. type: Object,
  78. default: () => ({})
  79. }
  80. },
  81. data () {
  82. return {
  83. innerLoading: false,
  84. templateList: [],
  85. type: null, // 类型
  86. isInDesign: false // 是否在设计页面
  87. }
  88. },
  89. methods: {
  90. init (type, isInDesign) {
  91. this.isInDesign = isInDesign
  92. this.type = type
  93. this.getTemplateList(type)
  94. },
  95. // 得到模板列表
  96. getTemplateList (type) {
  97. this.type = type
  98. this.$dataRoomAxios.get('/bigScreen/template/list', {
  99. type
  100. }).then((list) => {
  101. this.templateList = list
  102. })
  103. },
  104. // 从空白新建
  105. addNew () {
  106. this.$emit('addNew')
  107. },
  108. // 预览
  109. preview (id) {
  110. // 触发el-image的点击事件
  111. this.$refs['img' + id][0].showViewer = true
  112. },
  113. // 使用它作为模版
  114. useIt (id) {
  115. if (this.hasCreate) {
  116. this.$emit('useIt', id)
  117. } else {
  118. this.$confirm('使用该模板将会覆盖当前页面的所有内容,是否继续?', '提示', {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning',
  122. customClass: 'bs-el-message-box'
  123. }).then(() => {
  124. const className = this.type === 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO'
  125. this.innerLoading = true
  126. this.$dataRoomAxios.post(`/bigScreen/${this.type}/design/get/template`, {
  127. pageTemplateId: id,
  128. name: this.pageInfo.name,
  129. code: this.pageInfo.code,
  130. id: this.pageInfo.id,
  131. className
  132. }).then(res => {
  133. this.$emit('replaceItByTemplate', res)
  134. }).finally(() => {
  135. this.innerLoading = false
  136. })
  137. })
  138. }
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .template-list-wrap {
  145. display: grid;
  146. // 不固定列
  147. grid-template-columns: repeat(auto-fill, 140px);
  148. grid-gap: 20px;
  149. justify-content: center;
  150. .template-item {
  151. cursor: pointer;
  152. margin-right: 20px;
  153. .iconfont-div {
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. height: 140px;
  158. width: 140px;
  159. border: 1px solid #e5e5e5;
  160. color: #999999;
  161. .iconfont {
  162. font-size: 40px;
  163. }
  164. }
  165. .thumbnail {
  166. display: flex;
  167. justify-content: center;
  168. align-items: center;
  169. height: 140px;
  170. width: 140px;
  171. background: #f2f2f2;
  172. position: relative;
  173. .template-list-item-actions {
  174. position: absolute;
  175. width: 100%;
  176. height: 100%;
  177. left: 0;
  178. top: 0;
  179. cursor: default;
  180. text-align: center;
  181. color: #fff;
  182. opacity: 0;
  183. font-size: 20px;
  184. background-color: rgba(0,0,0,.5);
  185. transition: opacity .3s;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. cursor: pointer;
  190. i {
  191. margin: 0 10px;
  192. }
  193. }
  194. &:hover {
  195. .template-list-item-actions {
  196. opacity: 1;
  197. }
  198. }
  199. }
  200. .thumbnail img {
  201. width: 100%;
  202. }
  203. .name {
  204. margin-top: 10px;
  205. text-align: center;
  206. }
  207. }
  208. // 移动上去显示遮罩层预览和使用
  209. .template-choose-item {
  210. }
  211. }
  212. </style>