index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="divBox relative">
  3. <el-card
  4. :bordered="false"
  5. shadow="never"
  6. class="ivu-mt"
  7. :body-style="{ padding: 0 }"
  8. v-hasPermi="['platform:community:topic:page:list']"
  9. >
  10. <div class="padding-add">
  11. <el-form :inline="true" @submit.native.prevent>
  12. <el-form-item label="话题名称:">
  13. <el-input
  14. v-model.trim="name"
  15. placeholder="请输入话题名称"
  16. @keyup.enter.native="getList(1)"
  17. class="selWidth"
  18. size="small"
  19. clearable
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item label="推荐状态:">
  23. <el-select
  24. v-model="tableFrom.isHot"
  25. placeholder="请选择推荐状态"
  26. @change="getList(1)"
  27. size="small"
  28. class="selWidth"
  29. clearable
  30. >
  31. <el-option label="推荐" value="1"></el-option>
  32. <el-option label="不推荐" value="0"></el-option>
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" size="small" @click="getList(1)">查询</el-button>
  37. <el-button size="small" @click="reset()">重置</el-button>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </el-card>
  42. <el-card class="box-card mt14" :body-style="{ padding: '20px' }" :bordered="false" shadow="never">
  43. <el-button type="primary" size="small" v-hasPermi="['platform:community:topic:add']" @click="handlerOpenEdit(0)"
  44. >添加社区话题</el-button
  45. >
  46. <el-table
  47. v-loading="listLoading"
  48. :data="tableData.data"
  49. size="small"
  50. height="500px"
  51. :highlight-current-row="true"
  52. class="mt20"
  53. >
  54. <el-table-column prop="id" label="ID" min-width="50" />
  55. <el-table-column label="话题名称" prop="name" min-width="100" :show-overflow-tooltip="true"> </el-table-column>
  56. <el-table-column prop="countUse" label="文章数" min-width="100" />
  57. <el-table-column label="添加时间" min-width="120">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.createTime }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="是否推荐" fixed="right" min-width="90">
  63. <template slot-scope="scope">
  64. <el-switch
  65. v-if="checkPermi(['platform:community:topic:recommend:switch'])"
  66. v-model="scope.row.isHot"
  67. :active-value="1"
  68. :inactive-value="0"
  69. active-text="是"
  70. inactive-text="否"
  71. @click.native="onchangeIsShow(scope.row)"
  72. />
  73. <div v-else>{{ scope.row.isHot === 1 ? '推荐' : '不推荐' }}</div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" width="100" fixed="right">
  77. <template slot-scope="scope">
  78. <a @click="handlerOpenEdit(1, scope.row)" v-hasPermi="['platform:community:topic:update']">编辑</a>
  79. <el-divider direction="vertical"></el-divider>
  80. <a @click="handlerOpenDel(scope.row)" v-hasPermi="['platform:community:topic:delete']">删除</a>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <div class="block">
  85. <el-pagination
  86. background
  87. :page-sizes="[20, 40, 60, 80]"
  88. :page-size="tableFrom.limit"
  89. :current-page="tableFrom.page"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. :total="tableData.total"
  92. @size-change="handleSizeChange"
  93. @current-change="pageChange"
  94. />
  95. </div>
  96. </el-card>
  97. </div>
  98. </template>
  99. <script>
  100. // +---------------------------------------------------------------------
  101. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  102. // +---------------------------------------------------------------------
  103. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  104. // +---------------------------------------------------------------------
  105. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  106. // +---------------------------------------------------------------------
  107. // | Author: CRMEB Team <admin@crmeb.com>
  108. // +---------------------------------------------------------------------
  109. import * as community from '@/api/community';
  110. import { checkPermi } from '@/utils/permission'; // 权限判断函数
  111. export default {
  112. data() {
  113. return {
  114. form: {},
  115. rules: {},
  116. tableFrom: {
  117. page: 1,
  118. limit: 20,
  119. name: '',
  120. isHot: '',
  121. },
  122. name: '',
  123. tableData: {
  124. data: [],
  125. total: 0,
  126. },
  127. listLoading: false,
  128. keyNum: 0,
  129. id: 0,
  130. };
  131. },
  132. mounted() {
  133. if (checkPermi(['platform:community:topic:page:list'])) this.getList();
  134. },
  135. methods: {
  136. checkPermi,
  137. onchangeIsShow(row) {
  138. community.communityTopicRecommendApi(row.id).then((res) => {
  139. this.$message.success('操作成功');
  140. this.getList();
  141. });
  142. },
  143. // 列表
  144. getList(num) {
  145. this.tableFrom.page = num ? num : this.tableFrom.page;
  146. this.tableFrom.name = encodeURIComponent(this.name);
  147. this.listLoading = true;
  148. community
  149. .communityTopicListApi(this.tableFrom)
  150. .then((res) => {
  151. this.tableData.data = res.list;
  152. this.tableData.total = res.total;
  153. this.listLoading = false;
  154. })
  155. .catch((res) => {
  156. this.listLoading = false;
  157. });
  158. },
  159. reset() {
  160. this.tableFrom.name = '';
  161. this.tableFrom.isHot = '';
  162. this.name = '';
  163. this.getList(1);
  164. },
  165. pageChange(page) {
  166. this.tableFrom.page = page;
  167. this.getList();
  168. },
  169. handleSizeChange(val) {
  170. this.tableFrom.limit = val;
  171. this.getList(1);
  172. },
  173. handlerOpenEdit(isCreate, editDate) {
  174. const _this = this;
  175. this.id = editDate ? editDate.id : 0;
  176. this.$modalParserFrom(
  177. isCreate === 0 ? '新建话题' : '编辑话题',
  178. 'communityTopics',
  179. isCreate,
  180. isCreate === 0
  181. ? {
  182. id: 0,
  183. name: '',
  184. handlingFee: '',
  185. }
  186. : Object.assign({}, editDate),
  187. function (formValue) {
  188. _this.submit(formValue);
  189. _this.resetForm(formValue);
  190. },
  191. (this.keyNum = Math.random()),
  192. );
  193. },
  194. submit(formValue) {
  195. const data = {
  196. id: this.id,
  197. name: formValue.name,
  198. };
  199. !this.id
  200. ? community
  201. .communityTopicAddApi(data)
  202. .then((res) => {
  203. this.$message.success('操作成功');
  204. this.$msgbox.close();
  205. this.getList();
  206. })
  207. .catch(() => {
  208. this.loading = false;
  209. })
  210. : community
  211. .communityTopicUpdateApi(data)
  212. .then((res) => {
  213. this.$message.success('操作成功');
  214. this.$msgbox.close();
  215. this.getList();
  216. })
  217. .catch(() => {
  218. this.loading = false;
  219. });
  220. },
  221. handlerOpenDel(rowData) {
  222. this.$modalSure('删除当前话题吗?删除话题之后,与此相关的文章将取消关联话题!').then(() => {
  223. community.communityTopicDelApi(rowData.id).then((data) => {
  224. this.$message.success('删除话题成功');
  225. if (this.tableData.data.length === 1 && this.tableFrom.page > 1)
  226. this.tableFrom.page = this.tableFrom.page - 1;
  227. this.getList();
  228. });
  229. });
  230. },
  231. },
  232. };
  233. </script>
  234. <style>
  235. .alert_title {
  236. margin-right: 10px;
  237. }
  238. </style>