index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div :class="{'m-container': type === 'DEFAULT'}">
  3. <h2 v-if="type === 'DEFAULT'">
  4. <el-page-header @back="onCancel" :content="detailName"></el-page-header>
  5. </h2>
  6. <div class="m-core">
  7. <div class="buttons">
  8. <auth :auths="['photo/add']">
  9. <el-button type="primary" @click="openUpload()">{{type === 'DEFAULT' ? '上传照片' : '上传证书'}}</el-button>
  10. </auth>
  11. <auth :auths="['photo/batchUpdate']">
  12. <el-button type="primary" :disabled="list.length == 0" v-if="!editing" @click="changeMode()">{{type === 'DEFAULT' ? '编辑照片' : '编辑证书'}}</el-button>
  13. </auth>
  14. <auth :auths="['photo/del']">
  15. <el-button type="danger" v-if="editing" @click="remove()">{{type === 'DEFAULT' ? '删除照片' : '删除证书'}}</el-button>
  16. </auth>
  17. <el-button type="primary" v-if="editing" @click="confirm()">确定</el-button>
  18. <el-button type="primary" v-if="editing" @click="cancel()">取消</el-button>
  19. </div>
  20. <el-alert
  21. v-if="editing"
  22. type="info"
  23. class="alert"
  24. :closable="false">
  25. <div slot="title">
  26. <el-button class="btn" type="text" :disabled="list.length === checked.length" @click="checkAll()">全选</el-button>
  27. <el-button class="btn" type="text" :disabled="!checked.length" @click="checked = []">取消选择</el-button>
  28. <span>共{{list.length}}条, 已选择{{checked.length}}条</span>
  29. </div>
  30. </el-alert>
  31. <el-checkbox-group v-model="checked">
  32. <draggable :list="list" :disabled="!editing" style="display: flex;">
  33. <div
  34. v-for="(item) in list"
  35. :key="item.url"
  36. class="img-container"
  37. >
  38. <auth :auths="['photo/del']">
  39. <div v-if="editing" class="ctrl-bar">
  40. <el-checkbox class="check" :label="item.id"></el-checkbox>
  41. <i class="el-icon-view" :class="{active: views.includes(item.id)}" @click="setView(item)"></i>
  42. </div>
  43. <div v-else class="ctrl-bar-view">
  44. <el-tooltip effect="dark" content="设为封面" placement="top" :open-delay=".5">
  45. <i class="el-icon-picture-outline-round" @click="setCover(item)" v-if="type === 'DEFAULT'"></i>
  46. <i v-else></i>
  47. </el-tooltip>
  48. <el-tooltip effect="dark" :content="views.includes(item.id) ? '设为不可见' : '设为可见'" placement="top" :open-delay=".5">
  49. <i class="el-icon-view" :class="{active: views.includes(item.id)}" @click="setViewItem(item)"></i>
  50. </el-tooltip>
  51. </div>
  52. </auth>
  53. <el-image
  54. :src="item.url"
  55. class="img"
  56. :preview-src-list="list.map(item => item.url)">
  57. </el-image>
  58. <el-tooltip v-if="!editing" class="item" effect="dark" :content="item.name" placement="top" :open-delay=".5">
  59. <div class="name">{{item.name}}</div>
  60. </el-tooltip>
  61. <el-input class="nameinput" v-else v-model="item.name" size="mini" :placeholder="'请输入' + (type === 'DEFAULT' ? '照片' : '证书') + '名称'" clearable/>
  62. </div>
  63. </draggable>
  64. </el-checkbox-group>
  65. <empty v-if="list.length == 0"/>
  66. </div>
  67. <el-dialog
  68. :title="type === 'DEFAULT' ? '上传照片' : '上传证书'"
  69. :visible.sync="uploadVisible"
  70. v-if="uploadVisible"
  71. >
  72. <upload-popup
  73. @close="uploadVisible = false"
  74. @submited="submited"
  75. :name="$route.query.name"
  76. :query="queryIdOrType"
  77. />
  78. </el-dialog>
  79. </div>
  80. </template>
  81. <script>
  82. import draggable from 'vuedraggable'
  83. import uploadPopup from '@/views/resetTeaming/components/training-photos/upload'
  84. import { photoQueryPage, photoDel, photoUpdate, photoAlbumUpdate } from '@/views/resetTeaming/components/training-photos/api'
  85. export default {
  86. props: {
  87. type: {
  88. type: String,
  89. default: 'DEFAULT'
  90. },
  91. },
  92. components: {
  93. 'upload-popup': uploadPopup,
  94. draggable,
  95. },
  96. computed: {
  97. detailName() {
  98. return this.$route.query.name || '相册详情'
  99. },
  100. queryIdOrType() {
  101. const id = this.$route.query.pid
  102. if (this.type === 'DEFAULT') {
  103. return {
  104. id,
  105. type: this.type,
  106. }
  107. }
  108. return {
  109. type: this.type,
  110. musicGroupId: this.$route.query.id,
  111. }
  112. },
  113. },
  114. data() {
  115. return {
  116. views: [],
  117. checked: [],
  118. uploadVisible: false,
  119. list: [],
  120. editing: false,
  121. }
  122. },
  123. mounted() {
  124. console.log(this.$route)
  125. this.FetchList()
  126. },
  127. methods: {
  128. onCancel() {
  129. this.$store.dispatch("delVisitedViews", this.$route);
  130. if (this.$route.query.returnUrl) {
  131. this.$router.push(this.$route.query.returnUrl);
  132. }
  133. },
  134. openUpload() {
  135. this.uploadVisible = true
  136. },
  137. setInitViwes() {
  138. this.views = this.list.filter(item => item.clientShow).map(item => item.id)
  139. },
  140. async setCover(item) {
  141. try {
  142. await this.$confirm('是否确认设置为封面?', '提示')
  143. await photoAlbumUpdate({
  144. ...this.queryIdOrType,
  145. coverUrl: item.url
  146. })
  147. this.$message.success('设置成功')
  148. this.FetchList()
  149. } catch (error) {}
  150. },
  151. async setViewItem(item) {
  152. try {
  153. await this.$confirm('是否确认修改可见状态?', '提示')
  154. await photoUpdate([{
  155. ...item,
  156. clientShow: +!item.clientShow
  157. }])
  158. this.$message.success('设置成功')
  159. this.FetchList()
  160. } catch (error) {}
  161. },
  162. changeMode() {
  163. this.checked = []
  164. this.setInitViwes()
  165. this.editing = true
  166. },
  167. cancel() {
  168. this.editing = false
  169. this.list = this.list.sort((a, b) => a.order - b.order)
  170. },
  171. submited() {
  172. this.FetchList()
  173. },
  174. setView(item){
  175. const indexOf = this.views.indexOf(item.id)
  176. if (indexOf > -1) {
  177. this.views.splice(indexOf, 1)
  178. } else {
  179. this.views.push(item.id)
  180. }
  181. },
  182. checkAll() {
  183. this.checked = this.list.map(item => item.id)
  184. },
  185. async FetchList() {
  186. try {
  187. const res = await photoQueryPage({...this.queryIdOrType, photoAlbumId: this.queryIdOrType.id})
  188. // console.log(res.data.rows)
  189. this.list = res.data.rows
  190. this.setInitViwes()
  191. } catch (error) {}
  192. },
  193. async confirm() {
  194. try {
  195. await this.$confirm('是否确认修改照片信息?', '提示')
  196. const data = this.list.map((item, index) => ([{
  197. ...item,
  198. order: index,
  199. clientShow: +this.views.includes(item.id)
  200. }]))
  201. await photoUpdate(data)
  202. this.editing = false
  203. this.$message.success('修改成功')
  204. this.FetchList()
  205. } catch (error) {
  206. console.log(error)
  207. }
  208. },
  209. async remove() {
  210. try {
  211. await this.$confirm('是否确认删除已选照片?', '提示')
  212. await photoDel({
  213. ids: this.checked.join(',')
  214. })
  215. this.$message.success('删除成功')
  216. this.editing = false
  217. this.FetchList()
  218. } catch (error) {}
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="less" scoped>
  224. .img-container{
  225. display: inline-flex;
  226. margin-right: 20px;
  227. margin-top: 20px;
  228. flex-direction: column;
  229. text-align: center;
  230. position: relative;
  231. cursor: move;
  232. >.name{
  233. width: 150px;
  234. height: 30px;
  235. line-height: 30px;
  236. text-align: center;
  237. margin-top: 10px;
  238. color: rgba(0, 0, 0, .65);
  239. overflow: hidden;
  240. text-overflow: ellipsis;
  241. white-space: pre;
  242. font-size: 14px;
  243. }
  244. >.nameinput{
  245. width: 150px;
  246. margin-top: 10px;
  247. }
  248. }
  249. .ctrl-bar,
  250. .ctrl-bar-view{
  251. background-color: rgba(0, 0, 0, .45);
  252. height: 30px;
  253. position: absolute;
  254. top: 0;
  255. width: 100%;
  256. z-index: 1;
  257. display: flex;
  258. justify-content: space-between;
  259. align-items: center;
  260. padding: 0 15px;
  261. }
  262. .ctrl-bar-view{
  263. opacity: 0;
  264. visibility: hidden;
  265. transition: all .3s;
  266. }
  267. .img-container:hover{
  268. .ctrl-bar-view{
  269. opacity: 1;
  270. visibility: visible;
  271. }
  272. }
  273. .el-icon-view,
  274. .el-icon-picture-outline-round{
  275. font-size: 14px;
  276. color: #fff;
  277. cursor: pointer;
  278. &.active{
  279. color: #14928A;
  280. }
  281. }
  282. .switch{
  283. position: absolute;
  284. top: 10px;
  285. right: 10px;
  286. z-index: 1;
  287. }
  288. .img{
  289. width: 150px;
  290. height: 150px;
  291. border-radius: 3px;
  292. }
  293. .alert{
  294. margin-top: 20px;
  295. }
  296. .btn{
  297. padding: 0;
  298. }
  299. </style>