ImagePost.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <el-row>
  3. <el-row :md="6" :sm="12" :xs="12">
  4. <el-table
  5. :data="dataList"
  6. style="width: 100%"
  7. >
  8. <el-table-column
  9. type="index"
  10. />
  11. <el-table-column
  12. prop="coverUrl"
  13. label="相册封面"
  14. width="90"
  15. >
  16. <template slot-scope="scope">
  17. <el-image
  18. lazy
  19. fit="cover"
  20. class="coverImg"
  21. :src="scope.row.coverUrl"
  22. />
  23. </template>
  24. </el-table-column>
  25. <el-table-column
  26. prop="createdAt"
  27. label="发布时间"
  28. />
  29. <el-table-column
  30. prop="albumName"
  31. label="相册名字"
  32. width="180"
  33. >
  34. <template slot-scope="scope">
  35. <router-link target="_blank" :to="`/image/album/${scope.row.albumId}`">
  36. <span>{{ scope.row.albumName }}</span>
  37. </router-link>
  38. </template>
  39. </el-table-column>
  40. <el-table-column
  41. prop="total"
  42. label="图片数量"
  43. />
  44. <el-table-column
  45. prop="scope"
  46. label="可见范围"
  47. >
  48. <template slot-scope="scope">
  49. <el-tooltip class="item" effect="dark" content="点击修改可见范围" placement="top-end">
  50. <el-button
  51. v-if="scope.row.scope === 1"
  52. size="mini"
  53. @click="handleScope(scope.$index, scope.row)"
  54. >本人可见</el-button>
  55. <el-button
  56. v-else-if="scope.row.scope === 2"
  57. size="mini"
  58. type="success"
  59. @click="handleScope(scope.$index, scope.row)"
  60. >所有人可见</el-button>
  61. <el-button
  62. v-else-if="scope.row.scope === 3"
  63. size="mini"
  64. type="warning"
  65. @click="handleScope(scope.$index, scope.row)"
  66. >VIP 可见</el-button>
  67. <el-button
  68. v-else
  69. size="mini"
  70. type="danger"
  71. @click="handleScope(scope.$index, scope.row)"
  72. >验证码可见</el-button>
  73. </el-tooltip>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作">
  77. <template slot-scope="scope">
  78. <el-button
  79. size="mini"
  80. @click="handleEdit(scope.$index, scope.row)"
  81. >编辑</el-button>
  82. <el-button
  83. size="mini"
  84. type="danger"
  85. @click="handleDelete(scope.$index, scope.row)"
  86. >删除</el-button>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <!-- 修改可见范围对话框 -->
  91. <el-dialog
  92. append-to-body
  93. :visible.sync="showEditScopeDialog"
  94. width="30%"
  95. center
  96. >
  97. <el-card class="box-card">
  98. <div slot="header" class="clearfix">
  99. <span>修改相册可见范围</span>
  100. <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateScope">更新</el-button>
  101. </div>
  102. <div class="text item">
  103. <el-select v-model="form.scope" placeholder="选择可见范围">
  104. <el-option label="本人可见" value="1" />
  105. <el-option label="所有人可见" value="2" />
  106. <el-option label="VIP 可见" value="3" />
  107. <el-option label="验证码可见" value="4" />
  108. </el-select>
  109. </div>
  110. </el-card>
  111. </el-dialog>
  112. </el-row>
  113. <el-row>
  114. <el-pagination
  115. background
  116. :small="screenWidth <= 768"
  117. layout="prev, pager, next"
  118. :page-size="pageSize"
  119. :current-page="currentPage"
  120. :total="totalSize"
  121. @current-change="handleCurrentChange"
  122. @prev-click="handleCurrentChange"
  123. @next-click="handleCurrentChange"
  124. />
  125. </el-row>
  126. </el-row>
  127. </template>
  128. <script>
  129. import { updateAlbumScope, deleteAlbum, getUserAlbums } from '@/api/image'
  130. export default {
  131. name: 'ImagePost',
  132. data() {
  133. return {
  134. // 屏幕宽度, 为了控制分页条的大小
  135. screenWidth: document.body.clientWidth,
  136. currentPage: 1,
  137. pageSize: 12,
  138. totalSize: 0,
  139. dataList: [],
  140. // **********************************************************************
  141. showEditScopeDialog: false,
  142. form: {
  143. albumId: null,
  144. scope: 1
  145. }
  146. }
  147. },
  148. created() {
  149. document.title = '相册稿件'
  150. this.getData()
  151. },
  152. methods: {
  153. handleCurrentChange(pageNumber) {
  154. this.currentPage = pageNumber
  155. this.getData()
  156. // 回到顶部
  157. scrollTo(0, 0)
  158. },
  159. getData() {
  160. this.dataList = []
  161. getUserAlbums(this.currentPage).then(resp => {
  162. if (resp.code === 0) {
  163. this.dataList = resp.data.list
  164. this.totalSize = resp.data.totalSize
  165. } else {
  166. this.$notify({
  167. title: '提示',
  168. message: resp.msg,
  169. type: 'warning',
  170. duration: 3000
  171. })
  172. }
  173. })
  174. },
  175. handleScope(index, row) {
  176. this.form.albumId = row.albumId
  177. this.form.scope = '' + row.scope
  178. this.showEditScopeDialog = true
  179. },
  180. handleEdit(index, row) {
  181. const path = '/my/post/edit/album/' + row.albumId
  182. this.$router.push(path)
  183. },
  184. handleDelete(index, row) {
  185. this.$confirm('确定要删除 ' + row.albumName + ' 相册?', '提示', {
  186. confirmButtonText: '确定',
  187. cancelButtonText: '取消',
  188. type: 'warning'
  189. }).then(() => {
  190. deleteAlbum(row.albumId).then(res => {
  191. if (res.code === 0) {
  192. this.$notify({
  193. title: '相册稿件已删除',
  194. type: 'warning',
  195. duration: 3000
  196. })
  197. // this.$router.go(0)
  198. }
  199. })
  200. }).catch(() => {
  201. this.$message({
  202. type: 'info',
  203. message: '已取消'
  204. })
  205. })
  206. },
  207. onUpdateScope() {
  208. this.showEditScopeDialog = false
  209. updateAlbumScope(this.form).then(res => {
  210. if (res.code === 0) {
  211. this.$notify({
  212. title: '提示',
  213. message: '相册可见范围已更新',
  214. type: 'warning',
  215. duration: 3000
  216. })
  217. }
  218. }).catch(error => {
  219. this.$notify({
  220. title: '提示',
  221. message: error.message,
  222. type: 'warning',
  223. duration: 3000
  224. })
  225. })
  226. }
  227. }
  228. }
  229. </script>
  230. <style>
  231. /*处于手机屏幕时*/
  232. @media screen and (max-width: 768px) {
  233. .tit {
  234. font-weight: 600;
  235. font-size: 12px;
  236. height: 32px;
  237. }
  238. .time {
  239. font-size: 10px;
  240. color: #999;
  241. }
  242. .num {
  243. font-size: 9px;
  244. padding-top: 3px;
  245. }
  246. .bottom {
  247. margin-top: 2px;
  248. line-height: 7px;
  249. }
  250. .coverImg {
  251. height: 120px !important;
  252. }
  253. }
  254. .coverImg {
  255. width: 100%;
  256. height: 90px;
  257. display: block;
  258. }
  259. </style>