doum
2026-06-18 93de43267e1663031fe5dc2f5ae40d128a182a76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
  <TableLayout :permissions="['business:ywh5banner:query']">
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="88px" inline>
      <el-form-item label="标题" prop="title">
        <el-input v-model="searchForm.title" placeholder="请输入标题" clearable @keypress.enter.native="search" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="searchForm.status" clearable placeholder="全部">
          <el-option :value="0" label="启用" />
          <el-option :value="1" label="禁用" />
        </el-select>
      </el-form-item>
      <section>
        <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
        <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
      </section>
    </el-form>
 
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <li>
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="$refs.editWindow.open('新建轮播图')"
            v-permissions="['business:ywh5banner:create']"
          >新建</el-button>
        </li>
        <li>
          <el-button
            icon="el-icon-delete"
            @click="deleteByIdInBatch"
            v-permissions="['business:ywh5banner:delete']"
          >批量删除</el-button>
        </li>
      </ul>
 
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="48" />
        <el-table-column label="预览" width="160" align="center">
          <template slot-scope="{ row }">
            <el-image
              v-if="row.imageUrl"
              :src="row.imageUrl"
              :preview-src-list="[row.imageUrl]"
              fit="cover"
              class="banner-thumb"
            />
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" label="标题" min-width="140" show-overflow-tooltip />
        <el-table-column prop="sortnum" label="排序" width="80" align="center" />
        <el-table-column label="状态" width="100" align="center">
          <template slot-scope="{ row }">
            <el-switch
              v-model="row.status"
              :active-value="0"
              :inactive-value="1"
              :disabled="!containPermissions(['business:ywh5banner:update'])"
              @change="changeStatus(row)"
            />
          </template>
        </el-table-column>
        <el-table-column prop="linkUrl" label="跳转链接" min-width="160" show-overflow-tooltip />
        <el-table-column prop="editDate" label="更新时间" width="168" align="center" />
        <el-table-column label="操作" width="140" align="center" fixed="right">
          <template slot-scope="{ row }">
            <el-button
              type="text"
              @click="$refs.editWindow.open('编辑轮播图', row)"
              v-permissions="['business:ywh5banner:update']"
            >编辑</el-button>
            <el-button
              type="text"
              class="red"
              @click="deleteById(row)"
              v-permissions="['business:ywh5banner:delete']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
 
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      />
    </template>
 
    <YwH5BannerEdit ref="editWindow" @success="handlePageChange" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import YwH5BannerEdit from './components/YwH5BannerEdit'
import { updateById } from '@/api/business/ywh5banner'
import { Message } from 'element-ui'
 
export default {
  name: 'YwH5Banner',
  extends: BaseTable,
  components: { TableLayout, Pagination, YwH5BannerEdit },
  data () {
    return {
      searchForm: {
        title: '',
        status: null
      }
    }
  },
  created () {
    this.config({
      module: 'H5轮播图',
      api: '/business/ywh5banner',
      'field.id': 'id',
      'field.main': 'title'
    })
    this.search()
  },
  methods: {
    buildSearchModel () {
      const model = {}
      if (this.searchForm.title) model.title = this.searchForm.title
      if (this.searchForm.status !== null && this.searchForm.status !== '') {
        model.status = this.searchForm.status
      }
      return model
    },
    reset () {
      this.searchForm = { title: '', status: null }
      this.search()
    },
    handlePageChange (pageIndex) {
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      this.api.fetchList({
        page: this.tableData.pagination.pageIndex,
        capacity: this.tableData.pagination.pageSize,
        model: this.buildSearchModel(),
        sorts: this.tableData.sorts
      })
        .then(data => {
          this.tableData.list = data.records
          this.tableData.pagination.total = data.total
        })
        .catch(() => {})
        .finally(() => { this.isWorking.search = false })
    },
    changeStatus (row) {
      updateById({ id: row.id, status: row.status })
        .then(() => {
          Message.success('状态已更新')
        })
        .catch(() => {
          row.status = row.status === 0 ? 1 : 0
        })
    }
  }
}
</script>
 
<style scoped>
.banner-thumb {
  width: 128px;
  height: 56px;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}
 
.red {
  color: #f56c6c;
}
</style>