ImagePost.vue 9.5 KB

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