index.vue 4.7 KB

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