Index.vue 6.1 KB

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