index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="app-container">
  3. <div style="width: 400px">
  4. <el-image :src="require('@/assets/images/ohplay/search.png')" />
  5. <el-image :class="['border', active === item.id ? 'active' : '']" v-for="item in img" :key="item.id"
  6. :src="item.url" @click="getActive(item.id)" />
  7. <el-image :src="require('@/assets/images/ohplay/comment.png')" />
  8. </div>
  9. <keep-alive>
  10. <div class="isShow">
  11. <el-button v-if="isShow()" type="primary" icon="el-icon-plus" @click="getAdd"
  12. v-hasPermi="['ohplay:operation:add']">添加</el-button>
  13. <el-form label-width="100px" v-for="(item, index) in list" :key="index">
  14. <el-link :underline="false" class="close" icon="el-icon-close" @click="getDelete(item.id, index)" />
  15. <el-form-item :label="label + (index + 1)" />
  16. <el-form-item v-if="active === 3" label="文字:">
  17. <el-input v-model="item.script" placeholder="请输入快捷按钮文字" />
  18. </el-form-item>
  19. <el-form-item v-else label="Banner:">
  20. <Upload listType="picture-card" :url="item.banner" :width="343" :height="140" @upload="getUpload($event, index)" />
  21. </el-form-item>
  22. <el-form-item label="选择日期:">
  23. <el-date-picker v-model="item.date" size="small" type="datetimerange" start-placeholder="开始时间"
  24. end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" />
  25. </el-form-item>
  26. <el-form-item label="跳转:">
  27. <el-select v-model="item.skip" placeholder="请选择跳转页面">
  28. <el-option v-for="item in typeOptions" :key="item.value" :label="item.label"
  29. :value="Number(item.value)" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="网址:">
  33. <el-input v-model="item.skipUrl" placeholder="请输入网址" />
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" @click="getSubmit(item, index)"
  37. v-hasPermi="['ohplay:operation:submit']">确定</el-button>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </keep-alive>
  42. </div>
  43. </template>
  44. <script>
  45. import { create, list, remove, edit } from '@/api/ohplay/operation'
  46. export default {
  47. data() {
  48. return {
  49. img: [{
  50. id: 1,
  51. url: require('@/assets/images/ohplay/banner.png')
  52. }, {
  53. id: 2,
  54. url: require('@/assets/images/ohplay/pop.png')
  55. }, {
  56. id: 3,
  57. url: require('@/assets/images/ohplay/shortcut.png')
  58. }],
  59. active: 1,
  60. label: '广告位',
  61. // 列表
  62. list: [],
  63. // 跳转类型
  64. typeOptions: [{
  65. value: 0,
  66. label: '指定页面'
  67. }, {
  68. value: 1,
  69. label: '指定URL'
  70. }]
  71. }
  72. },
  73. mounted() {
  74. this.getList()
  75. },
  76. methods: {
  77. // 切换选中位置
  78. getActive(id) {
  79. if (this.active !== id) {
  80. this.active = id
  81. this.label = id === 1 ? '广告位' : id === 2 ? '推广位' : '快捷位'
  82. this.getList()
  83. }
  84. },
  85. // 添加
  86. getAdd() {
  87. this.list.push({})
  88. },
  89. // 隐藏添加按钮
  90. isShow() {
  91. return this.active === 3 ? this.list.length < 4 ? true : false : this.list.length < 6 ? true : false
  92. },
  93. // 删除
  94. getDelete(id, index) {
  95. if (id) {
  96. this.$confirm('是否删除?', '提示', {
  97. 'confirmButtonText': '确定',
  98. 'cancelButtonText': '取消',
  99. type: 'warning'
  100. }).then(() => {
  101. remove(id).then(res => {
  102. if (res.code === 0) {
  103. this.$message.success('删除成功!')
  104. this.getList()
  105. }
  106. })
  107. })
  108. } else {
  109. this.list.splice(index, 1)
  110. }
  111. },
  112. // 列表
  113. getList() {
  114. let type = this.active === 1 ? 2 : this.active === 2 ? 0 : 1
  115. this.list = []
  116. list({
  117. type: type
  118. }).then(res => {
  119. if (res.code === 0) {
  120. if (res.data) {
  121. res.data.map(i => {
  122. this.list.push({
  123. date: [i.startCreateTime, i.endCreateTime],
  124. ...i
  125. })
  126. })
  127. }
  128. }
  129. })
  130. },
  131. // 上传图片
  132. getUpload(e, index) {
  133. this.list[index].banner = e.file
  134. },
  135. // 新增 编辑
  136. getSubmit(item, index) {
  137. let form = {
  138. type: this.active === 1 ? 2 : this.active === 2 ? 0 : 1,
  139. startCreateTime: item.date[0],
  140. endCreateTime: item.date[1],
  141. sort: index + 1,
  142. skip: item.skip,
  143. skipUrl: item.skipUrl,
  144. script: item.script,
  145. banner: item.banner
  146. }
  147. if (item.id) {
  148. form.id = item.id
  149. edit(form).then(res => {
  150. if (res.code === 0) {
  151. this.$message.success('修改成功!')
  152. this.getList()
  153. }
  154. })
  155. } else {
  156. create(form).then(res => {
  157. if (res.code === 0) {
  158. this.$message.success('创建成功!')
  159. this.getList()
  160. }
  161. })
  162. }
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .app-container {
  169. display: flex;
  170. }
  171. .el-image {
  172. background: #000;
  173. display: block;
  174. }
  175. .isShow {
  176. width: calc(100% - 400px);
  177. margin-left: 20px;
  178. .el-form {
  179. width: 500px;
  180. border: 1px solid #dcdfe6;
  181. padding: 20px;
  182. box-shadow: 5px 5px 5px 0px #dcdfe6;
  183. margin: 0 20px 20px 0;
  184. position: relative;
  185. .close {
  186. position: absolute;
  187. top: 20px;
  188. right: 20px;
  189. z-index: 99;
  190. }
  191. }
  192. }
  193. .border {
  194. position: relative;
  195. border-top: 1px solid yellow;
  196. border-right: 1px solid yellow;
  197. border-left: 1px solid yellow;
  198. }
  199. .border:nth-child(4) {
  200. border-bottom: 1px solid yellow;
  201. }
  202. .active::after {
  203. content: '';
  204. background: rgba(255, 255, 0, 0.3);
  205. position: absolute;
  206. top: 0;
  207. left: 0;
  208. width: 100%;
  209. height: 100%;
  210. }
  211. </style>