themeList.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <HeaderBar/>
  4. <div class="my-themes">
  5. <div class="container">
  6. <ul class="theme-list">
  7. <li class="theme-item create" @click="create">
  8. <div class="create-area">
  9. <p>创建作品</p>
  10. </div>
  11. </li>
  12. <template v-for="item in list">
  13. <li class="theme-item">
  14. <div class="thumb" >
  15. <img src="../../assets/images/default.png" alt="">
  16. <div class="cover">
  17. <div class="toolbar">
  18. <el-tooltip class="item" effect="dark" content="编辑" placement="top-start">
  19. <i @click="toEditor(item)" class="el-icon-edit"></i>
  20. </el-tooltip>
  21. <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
  22. <i @click.stop="deleteTheme(item)" class="el-icon-delete"></i>
  23. </el-tooltip>
  24. </div>
  25. <div class="preview" @click="showPreView(item._id)"><span>预 览</span></div>
  26. </div>
  27. </div>
  28. <div class="footer">
  29. <div class="title">{{item.title}}</div>
  30. <div class="content">{{item.description}}</div>
  31. </div>
  32. </li>
  33. </template>
  34. </ul>
  35. </div>
  36. </div>
  37. <PreView :itemId="itemId" @hideView="isShowPreView=false" v-if="isShowPreView"/>
  38. </div>
  39. </template>
  40. <script>
  41. import HeaderBar from '../../components/HeaderBar'
  42. import tools from '../../util/tools'
  43. import PreView from '../../components/PreView'
  44. export default {
  45. data () {
  46. return {
  47. isShowPreView: false,
  48. itemId: null
  49. }
  50. },
  51. computed: {
  52. list () {
  53. return this.$store.state.editor.themeList
  54. }
  55. },
  56. mounted () {
  57. this.$store.dispatch('getUserThemeList', 'spa')
  58. },
  59. methods: {
  60. toEditor (item) {
  61. this.$store.dispatch('setEditorTheme', item)
  62. this.$store.dispatch('setEditorPage', item.pages[0])
  63. this.$router.replace({ path: '/spaeditor', query: { itemId: item._id } })
  64. },
  65. deleteTheme (item) {
  66. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
  67. confirmButtonText: '确定',
  68. cancelButtonText: '取消',
  69. type: 'warning'
  70. }).then(() => {
  71. this.$store.dispatch('deleteTheme', item)
  72. this.$message({
  73. type: 'success',
  74. message: '删除成功!'
  75. })
  76. }).catch(() => {
  77. this.$message({
  78. type: 'info',
  79. message: '已取消删除'
  80. })
  81. })
  82. },
  83. create () {
  84. this.$store.dispatch('createTheme', 'spa')
  85. this.$store.dispatch('addPage')
  86. let $this = this
  87. this.$store.dispatch('saveTheme', tools.vue2json(this.$store.state.editor.editorTheme)).then(() => {
  88. this.$router.replace({ path: '/spaeditor', query: { itemId: $this.$store.state.editor.editorTheme._id } })
  89. })
  90. },
  91. showPreView (itemId) {
  92. this.isShowPreView = true
  93. this.itemId = itemId
  94. }
  95. },
  96. components: {
  97. HeaderBar, PreView
  98. }
  99. }
  100. </script>
  101. <style lang="less" scoped>
  102. .my-themes {
  103. width: 100%;
  104. height: 100%;
  105. background-color: #f2f5f6;
  106. }
  107. .my-themes .container {
  108. width: 1024px;
  109. margin: 0 auto;
  110. padding-top: 20px;
  111. }
  112. .my-themes .theme-list {
  113. overflow: hidden;
  114. }
  115. .theme-item {
  116. width: 230px;
  117. height: 328px;
  118. float: left;
  119. margin-right: 20px;
  120. margin-bottom: 20px;
  121. background: #fff;
  122. }
  123. .theme-item .thumb img {
  124. width: 100%;
  125. height: 230px;
  126. }
  127. .thumb {
  128. position: relative;
  129. .cover {
  130. display: none;
  131. position: absolute;
  132. background: #000;
  133. opacity: 0.5;
  134. width: 100%;
  135. height: 100%;
  136. top:0;
  137. .toolbar {
  138. color: #fff;
  139. text-align: right;
  140. cursor: pointer;
  141. padding: 10px;
  142. font-size: 18px;
  143. i {
  144. margin: 5px;
  145. }
  146. }
  147. .preview {
  148. text-align: center;
  149. margin-top:70px;
  150. span {
  151. border: 1px solid #fff;
  152. padding: 5px 10px;
  153. font-size: 20px;
  154. color: #fff;
  155. cursor: pointer;
  156. }
  157. }
  158. }
  159. }
  160. .thumb:hover {
  161. .cover {
  162. display: block;
  163. }
  164. }
  165. .theme-item .footer {
  166. height: 98px;
  167. padding: 10px;
  168. background-color: #fff;
  169. box-sizing: border-box;
  170. position: relative;
  171. }
  172. .theme-item .footer > .title {
  173. color: #4a4a4a;
  174. font-size: 14px;
  175. width: 100%;
  176. overflow: hidden;
  177. text-overflow: ellipsis;
  178. white-space: nowrap;
  179. }
  180. .theme-item .footer > .content {
  181. color: #83817b;
  182. margin-top: 12px;
  183. font-size: 14px;
  184. max-height: 40px;
  185. overflow: hidden;
  186. line-height: 1.5;
  187. }
  188. .footer .delete {
  189. position: absolute;
  190. right: 10px;
  191. bottom: 10px;
  192. }
  193. .theme-item.create {
  194. text-align: center;
  195. }
  196. .theme-item.create .create-area p {
  197. font-size: 20px;
  198. cursor: pointer;
  199. margin-top: 100px;
  200. }
  201. </style>