ImagePost.vue 9.0 KB

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