Index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="card-title">{{ $route.meta.title }}</div>
  4. <div class="table-operator">
  5. <!-- 搜索板块 -->
  6. <a-row class="row-item-search">
  7. <a-form class="search-form" :form="searchForm" layout="inline" @submit="handleSearch">
  8. <a-form-item label="文章标题">
  9. <a-input v-decorator="['title']" placeholder="请输入文章标题" />
  10. </a-form-item>
  11. <a-form-item label="文章分类">
  12. <a-select v-decorator="['categoryId', { initialValue: -1 }]">
  13. <a-select-option :value="-1">全部</a-select-option>
  14. <a-select-option
  15. v-for="(item, index) in categoryList"
  16. :key="index"
  17. :value="item.category_id"
  18. >{{ item.name }}</a-select-option>
  19. </a-select>
  20. </a-form-item>
  21. <a-form-item label="状态">
  22. <a-select v-decorator="['status', { initialValue: -1 }]">
  23. <a-select-option :value="-1">全部</a-select-option>
  24. <a-select-option :value="1">显示</a-select-option>
  25. <a-select-option :value="0">隐藏</a-select-option>
  26. </a-select>
  27. </a-form-item>
  28. <a-form-item class="search-btn">
  29. <a-button type="primary" icon="search" html-type="submit">搜索</a-button>
  30. </a-form-item>
  31. </a-form>
  32. </a-row>
  33. <!-- 操作板块 -->
  34. <div class="row-item-tab clearfix">
  35. <a-button
  36. v-if="$auth('/market/coupon/create')"
  37. type="primary"
  38. icon="plus"
  39. @click="handleAdd()"
  40. >新增</a-button>
  41. </div>
  42. </div>
  43. <s-table
  44. ref="table"
  45. rowKey="article_id"
  46. :loading="isLoading"
  47. :columns="columns"
  48. :data="loadData"
  49. :pageSize="15"
  50. :scroll="{ x: 1400 }"
  51. >
  52. <!-- 文章封面图 -->
  53. <span slot="image_url" slot-scope="text">
  54. <a title="点击查看原图" :href="text" target="_blank">
  55. <img height="50" :src="text" alt="封面图" />
  56. </a>
  57. </span>
  58. <!-- 文章标题 -->
  59. <span slot="stitle" slot-scope="text">
  60. <p class="twoline-hide" style="width: 270px;">{{ text }}</p>
  61. </span>
  62. <!-- 所属分类 -->
  63. <span slot="category" slot-scope="text">{{ text.name }}</span>
  64. <!-- 状态 -->
  65. <span slot="status" slot-scope="text">
  66. <a-tag :color="text ? 'green' : ''">{{ text ? '显示' : '隐藏' }}</a-tag>
  67. </span>
  68. <!-- 操作项 -->
  69. <span class="actions" slot="action" slot-scope="text, item">
  70. <a v-if="$auth('/market/coupon/update')" @click="handleEdit(item)">编辑</a>
  71. <a v-action:delete @click="handleDelete(item)">删除</a>
  72. </span>
  73. </s-table>
  74. <AddForm ref="AddForm" :categoryList="categoryList" @handleSubmit="handleRefresh" />
  75. <EditForm ref="EditForm" :categoryList="categoryList" @handleSubmit="handleRefresh" />
  76. </a-card>
  77. </template>
  78. <script>
  79. import { STable } from '@/components'
  80. import * as ArticleApi from '@/api/content/article'
  81. import * as CategoryApi from '@/api/content/article/category'
  82. // 表格表头
  83. const columns = [
  84. {
  85. title: 'ID',
  86. dataIndex: 'article_id'
  87. },
  88. {
  89. title: '封面图',
  90. dataIndex: 'image_url',
  91. scopedSlots: { customRender: 'image_url' }
  92. },
  93. {
  94. title: '文章标题',
  95. dataIndex: 'title',
  96. width: '320px',
  97. scopedSlots: { customRender: 'stitle' }
  98. },
  99. {
  100. title: '所属分类',
  101. dataIndex: 'category',
  102. scopedSlots: { customRender: 'category' }
  103. },
  104. {
  105. title: '实际阅读量',
  106. dataIndex: 'actual_views'
  107. },
  108. {
  109. title: '状态',
  110. dataIndex: 'status',
  111. scopedSlots: { customRender: 'status' }
  112. },
  113. {
  114. title: '排序',
  115. dataIndex: 'sort'
  116. },
  117. {
  118. title: '创建时间',
  119. width: '180px',
  120. dataIndex: 'create_time'
  121. },
  122. {
  123. title: '更新时间',
  124. width: '180px',
  125. dataIndex: 'update_time'
  126. },
  127. {
  128. title: '操作',
  129. dataIndex: 'action',
  130. width: '150px',
  131. fixed: 'right',
  132. scopedSlots: { customRender: 'action' }
  133. }
  134. ]
  135. export default {
  136. name: 'Index',
  137. components: { STable },
  138. data () {
  139. return {
  140. // 正在加载
  141. isLoading: false,
  142. // 当前表单元素
  143. searchForm: this.$form.createForm(this),
  144. // 分类列表
  145. categoryList: [],
  146. // 查询参数
  147. queryParam: {},
  148. // 表头
  149. columns,
  150. // 加载数据方法 必须为 Promise 对象
  151. loadData: param => ArticleApi.list({ ...param, ...this.queryParam }).then(response => response.data.list)
  152. }
  153. },
  154. created () {
  155. // 获取分类列表
  156. this.getCategoryList()
  157. },
  158. methods: {
  159. // 获取分类列表
  160. getCategoryList () {
  161. this.isLoading = true
  162. CategoryApi.list()
  163. .then(result => this.categoryList = result.data.list)
  164. .finally(() => this.isLoading = false)
  165. },
  166. // 确认搜索
  167. handleSearch (e) {
  168. e.preventDefault()
  169. this.searchForm.validateFields((error, values) => {
  170. if (!error) {
  171. this.queryParam = { ...this.queryParam, ...values }
  172. this.handleRefresh(true)
  173. }
  174. })
  175. },
  176. // 删除记录
  177. handleDelete (item) {
  178. const app = this
  179. const modal = this.$confirm({
  180. title: '您确定要删除该记录吗?',
  181. content: '删除后不可恢复',
  182. onOk () {
  183. return ArticleApi.deleted({ articleId: item.article_id })
  184. .then(result => {
  185. app.$message.success(result.message, 1.5)
  186. app.handleRefresh()
  187. })
  188. .finally(result => modal.destroy())
  189. }
  190. })
  191. },
  192. // 新增记录
  193. handleAdd () {
  194. this.$router.push('./create')
  195. },
  196. // 编辑记录
  197. handleEdit (item) {
  198. this.$router.push({ path: './update', query: { articleId: item.article_id } })
  199. },
  200. /**
  201. * 刷新列表
  202. * @param Boolean bool 强制刷新到第一页
  203. */
  204. handleRefresh (bool = false) {
  205. this.$refs.table.refresh(bool)
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="less" scoped>
  211. .ant-card-body {
  212. padding: 22px 29px 25px;
  213. }
  214. // 筛选tab
  215. .tab-list {
  216. margin-right: 20px;
  217. }
  218. </style>