You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

435 lines
14 KiB

  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="作者用户ID" prop="authorId">
  5. <el-input
  6. v-model="queryParams.authorId"
  7. placeholder="请输入作者用户ID"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="帖子标题" prop="title">
  13. <el-input
  14. v-model="queryParams.title"
  15. placeholder="请输入帖子标题"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="分类标签" prop="category">
  21. <el-input
  22. v-model="queryParams.category"
  23. placeholder="请输入分类标签"
  24. clearable
  25. @keyup.enter.native="handleQuery"
  26. />
  27. </el-form-item>
  28. <el-form-item label="是否含敏感词" prop="isSensitive">
  29. <el-input
  30. v-model="queryParams.isSensitive"
  31. placeholder="请输入是否含敏感词"
  32. clearable
  33. @keyup.enter.native="handleQuery"
  34. />
  35. </el-form-item>
  36. <el-form-item label="查看次数" prop="viewCount">
  37. <el-input
  38. v-model="queryParams.viewCount"
  39. placeholder="请输入查看次数"
  40. clearable
  41. @keyup.enter.native="handleQuery"
  42. />
  43. </el-form-item>
  44. <el-form-item label="发布时间" prop="publishedAt">
  45. <el-date-picker clearable
  46. v-model="queryParams.publishedAt"
  47. type="date"
  48. value-format="yyyy-MM-dd"
  49. placeholder="请选择发布时间">
  50. </el-date-picker>
  51. </el-form-item>
  52. <el-form-item label="最后回复时间" prop="lastReplyAt">
  53. <el-date-picker clearable
  54. v-model="queryParams.lastReplyAt"
  55. type="date"
  56. value-format="yyyy-MM-dd"
  57. placeholder="请选择最后回复时间">
  58. </el-date-picker>
  59. </el-form-item>
  60. <el-form-item label="创建时间" prop="createdAt">
  61. <el-date-picker clearable
  62. v-model="queryParams.createdAt"
  63. type="date"
  64. value-format="yyyy-MM-dd"
  65. placeholder="请选择创建时间">
  66. </el-date-picker>
  67. </el-form-item>
  68. <el-form-item label="更新时间" prop="updatedAt">
  69. <el-date-picker clearable
  70. v-model="queryParams.updatedAt"
  71. type="date"
  72. value-format="yyyy-MM-dd"
  73. placeholder="请选择更新时间">
  74. </el-date-picker>
  75. </el-form-item>
  76. <el-form-item>
  77. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  78. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  79. </el-form-item>
  80. </el-form>
  81. <el-row :gutter="10" class="mb8">
  82. <el-col :span="1.5">
  83. <el-button
  84. type="primary"
  85. plain
  86. icon="el-icon-plus"
  87. size="mini"
  88. @click="handleAdd"
  89. v-hasPermi="['system:posts:add']"
  90. >新增</el-button>
  91. </el-col>
  92. <el-col :span="1.5">
  93. <el-button
  94. type="success"
  95. plain
  96. icon="el-icon-edit"
  97. size="mini"
  98. :disabled="single"
  99. @click="handleUpdate"
  100. v-hasPermi="['system:posts:edit']"
  101. >修改</el-button>
  102. </el-col>
  103. <el-col :span="1.5">
  104. <el-button
  105. type="danger"
  106. plain
  107. icon="el-icon-delete"
  108. size="mini"
  109. :disabled="multiple"
  110. @click="handleDelete"
  111. v-hasPermi="['system:posts:remove']"
  112. >删除</el-button>
  113. </el-col>
  114. <el-col :span="1.5">
  115. <el-button
  116. type="warning"
  117. plain
  118. icon="el-icon-download"
  119. size="mini"
  120. @click="handleExport"
  121. v-hasPermi="['system:posts:export']"
  122. >导出</el-button>
  123. </el-col>
  124. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  125. </el-row>
  126. <el-table v-loading="loading" :data="postsList" @selection-change="handleSelectionChange">
  127. <el-table-column type="selection" width="55" align="center" />
  128. <el-table-column label="帖子ID" align="center" prop="postId" />
  129. <el-table-column label="作者用户ID" align="center" prop="authorId" />
  130. <el-table-column label="帖子类型:问答,经验分享" align="center" prop="postType" />
  131. <el-table-column label="帖子标题" align="center" prop="title" />
  132. <el-table-column label="帖子内容" align="center" prop="content" />
  133. <el-table-column label="分类标签" align="center" prop="category" />
  134. <el-table-column label="图片URL数组" align="center" prop="images" />
  135. <el-table-column label="视频URL" align="center" prop="videoUrl" />
  136. <el-table-column label="帖子状态" align="center" prop="status" />
  137. <el-table-column label="是否含敏感词" align="center" prop="isSensitive" />
  138. <el-table-column label="敏感词列表" align="center" prop="sensitiveWords" />
  139. <el-table-column label="审核备注" align="center" prop="auditRemark" />
  140. <el-table-column label="查看次数" align="center" prop="viewCount" />
  141. <el-table-column label="发布时间" align="center" prop="publishedAt" width="180">
  142. <template slot-scope="scope">
  143. <span>{{ parseTime(scope.row.publishedAt, '{y}-{m}-{d}') }}</span>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="最后回复时间" align="center" prop="lastReplyAt" width="180">
  147. <template slot-scope="scope">
  148. <span>{{ parseTime(scope.row.lastReplyAt, '{y}-{m}-{d}') }}</span>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
  152. <template slot-scope="scope">
  153. <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
  154. </template>
  155. </el-table-column>
  156. <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
  157. <template slot-scope="scope">
  158. <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
  159. </template>
  160. </el-table-column>
  161. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  162. <template slot-scope="scope">
  163. <el-button
  164. size="mini"
  165. type="text"
  166. icon="el-icon-edit"
  167. @click="handleUpdate(scope.row)"
  168. v-hasPermi="['system:posts:edit']"
  169. >修改</el-button>
  170. <el-button
  171. size="mini"
  172. type="text"
  173. icon="el-icon-delete"
  174. @click="handleDelete(scope.row)"
  175. v-hasPermi="['system:posts:remove']"
  176. >删除</el-button>
  177. </template>
  178. </el-table-column>
  179. </el-table>
  180. <pagination
  181. v-show="total>0"
  182. :total="total"
  183. :page.sync="queryParams.pageNum"
  184. :limit.sync="queryParams.pageSize"
  185. @pagination="getList"
  186. />
  187. <!-- 添加或修改帖子包含问答和经验分享对话框 -->
  188. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  189. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  190. <el-form-item label="作者用户ID" prop="authorId">
  191. <el-input v-model="form.authorId" placeholder="请输入作者用户ID" />
  192. </el-form-item>
  193. <el-form-item label="帖子标题" prop="title">
  194. <el-input v-model="form.title" placeholder="请输入帖子标题" />
  195. </el-form-item>
  196. <el-form-item label="帖子内容">
  197. <editor v-model="form.content" :min-height="192"/>
  198. </el-form-item>
  199. <el-form-item label="分类标签" prop="category">
  200. <el-input v-model="form.category" placeholder="请输入分类标签" />
  201. </el-form-item>
  202. <el-form-item label="视频URL" prop="videoUrl">
  203. <el-input v-model="form.videoUrl" type="textarea" placeholder="请输入内容" />
  204. </el-form-item>
  205. <el-form-item label="是否含敏感词" prop="isSensitive">
  206. <el-input v-model="form.isSensitive" placeholder="请输入是否含敏感词" />
  207. </el-form-item>
  208. <el-form-item label="审核备注" prop="auditRemark">
  209. <el-input v-model="form.auditRemark" type="textarea" placeholder="请输入内容" />
  210. </el-form-item>
  211. <el-form-item label="查看次数" prop="viewCount">
  212. <el-input v-model="form.viewCount" placeholder="请输入查看次数" />
  213. </el-form-item>
  214. <el-form-item label="发布时间" prop="publishedAt">
  215. <el-date-picker clearable
  216. v-model="form.publishedAt"
  217. type="date"
  218. value-format="yyyy-MM-dd"
  219. placeholder="请选择发布时间">
  220. </el-date-picker>
  221. </el-form-item>
  222. <el-form-item label="最后回复时间" prop="lastReplyAt">
  223. <el-date-picker clearable
  224. v-model="form.lastReplyAt"
  225. type="date"
  226. value-format="yyyy-MM-dd"
  227. placeholder="请选择最后回复时间">
  228. </el-date-picker>
  229. </el-form-item>
  230. <el-form-item label="创建时间" prop="createdAt">
  231. <el-date-picker clearable
  232. v-model="form.createdAt"
  233. type="date"
  234. value-format="yyyy-MM-dd"
  235. placeholder="请选择创建时间">
  236. </el-date-picker>
  237. </el-form-item>
  238. <el-form-item label="更新时间" prop="updatedAt">
  239. <el-date-picker clearable
  240. v-model="form.updatedAt"
  241. type="date"
  242. value-format="yyyy-MM-dd"
  243. placeholder="请选择更新时间">
  244. </el-date-picker>
  245. </el-form-item>
  246. </el-form>
  247. <div slot="footer" class="dialog-footer">
  248. <el-button type="primary" @click="submitForm"> </el-button>
  249. <el-button @click="cancel"> </el-button>
  250. </div>
  251. </el-dialog>
  252. </div>
  253. </template>
  254. <script>
  255. import { listPosts, getPosts, delPosts, addPosts, updatePosts } from "@/api/system/posts"
  256. export default {
  257. name: "Posts",
  258. data() {
  259. return {
  260. // 遮罩层
  261. loading: true,
  262. // 选中数组
  263. ids: [],
  264. // 非单个禁用
  265. single: true,
  266. // 非多个禁用
  267. multiple: true,
  268. // 显示搜索条件
  269. showSearch: true,
  270. // 总条数
  271. total: 0,
  272. // 帖子(包含问答和经验分享)表格数据
  273. postsList: [],
  274. // 弹出层标题
  275. title: "",
  276. // 是否显示弹出层
  277. open: false,
  278. // 查询参数
  279. queryParams: {
  280. pageNum: 1,
  281. pageSize: 10,
  282. authorId: null,
  283. postType: null,
  284. title: null,
  285. content: null,
  286. category: null,
  287. images: null,
  288. videoUrl: null,
  289. status: null,
  290. isSensitive: null,
  291. sensitiveWords: null,
  292. auditRemark: null,
  293. viewCount: null,
  294. publishedAt: null,
  295. lastReplyAt: null,
  296. createdAt: null,
  297. updatedAt: null
  298. },
  299. // 表单参数
  300. form: {},
  301. // 表单校验
  302. rules: {
  303. authorId: [
  304. { required: true, message: "作者用户ID不能为空", trigger: "blur" }
  305. ],
  306. postType: [
  307. { required: true, message: "帖子类型:问答,经验分享不能为空", trigger: "change" }
  308. ],
  309. title: [
  310. { required: true, message: "帖子标题不能为空", trigger: "blur" }
  311. ],
  312. content: [
  313. { required: true, message: "帖子内容不能为空", trigger: "blur" }
  314. ],
  315. }
  316. }
  317. },
  318. created() {
  319. this.getList()
  320. },
  321. methods: {
  322. /** 查询帖子(包含问答和经验分享)列表 */
  323. getList() {
  324. this.loading = true
  325. listPosts(this.queryParams).then(response => {
  326. this.postsList = response.rows
  327. this.total = response.total
  328. this.loading = false
  329. })
  330. },
  331. // 取消按钮
  332. cancel() {
  333. this.open = false
  334. this.reset()
  335. },
  336. // 表单重置
  337. reset() {
  338. this.form = {
  339. postId: null,
  340. authorId: null,
  341. postType: null,
  342. title: null,
  343. content: null,
  344. category: null,
  345. images: null,
  346. videoUrl: null,
  347. status: null,
  348. isSensitive: null,
  349. sensitiveWords: null,
  350. auditRemark: null,
  351. viewCount: null,
  352. publishedAt: null,
  353. lastReplyAt: null,
  354. createdAt: null,
  355. updatedAt: null
  356. }
  357. this.resetForm("form")
  358. },
  359. /** 搜索按钮操作 */
  360. handleQuery() {
  361. this.queryParams.pageNum = 1
  362. this.getList()
  363. },
  364. /** 重置按钮操作 */
  365. resetQuery() {
  366. this.resetForm("queryForm")
  367. this.handleQuery()
  368. },
  369. // 多选框选中数据
  370. handleSelectionChange(selection) {
  371. this.ids = selection.map(item => item.postId)
  372. this.single = selection.length!==1
  373. this.multiple = !selection.length
  374. },
  375. /** 新增按钮操作 */
  376. handleAdd() {
  377. this.reset()
  378. this.open = true
  379. this.title = "添加帖子(包含问答和经验分享)"
  380. },
  381. /** 修改按钮操作 */
  382. handleUpdate(row) {
  383. this.reset()
  384. const postId = row.postId || this.ids
  385. getPosts(postId).then(response => {
  386. this.form = response.data
  387. this.open = true
  388. this.title = "修改帖子(包含问答和经验分享)"
  389. })
  390. },
  391. /** 提交按钮 */
  392. submitForm() {
  393. this.$refs["form"].validate(valid => {
  394. if (valid) {
  395. if (this.form.postId != null) {
  396. updatePosts(this.form).then(response => {
  397. this.$modal.msgSuccess("修改成功")
  398. this.open = false
  399. this.getList()
  400. })
  401. } else {
  402. addPosts(this.form).then(response => {
  403. this.$modal.msgSuccess("新增成功")
  404. this.open = false
  405. this.getList()
  406. })
  407. }
  408. }
  409. })
  410. },
  411. /** 删除按钮操作 */
  412. handleDelete(row) {
  413. const postIds = row.postId || this.ids
  414. this.$modal.confirm('是否确认删除帖子(包含问答和经验分享)编号为"' + postIds + '"的数据项?').then(function() {
  415. return delPosts(postIds)
  416. }).then(() => {
  417. this.getList()
  418. this.$modal.msgSuccess("删除成功")
  419. }).catch(() => {})
  420. },
  421. /** 导出按钮操作 */
  422. handleExport() {
  423. this.download('system/posts/export', {
  424. ...this.queryParams
  425. }, `posts_${new Date().getTime()}.xlsx`)
  426. }
  427. }
  428. }
  429. </script>