index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="communityManage app-container">
  3. <div class="search">
  4. <div>
  5. <el-date-picker
  6. v-model="date"
  7. size="small"
  8. class="item-width-350"
  9. value-format="yyyy-MM-dd HH:mm:ss"
  10. type="datetimerange"
  11. range-separator="至"
  12. :default-time="['00:00:00', '23:59:59']"
  13. start-placeholder="开始日期"
  14. end-placeholder="结束日期">
  15. </el-date-picker>
  16. <el-button
  17. class="ml10"
  18. type="primary"
  19. size="small"
  20. icon="el-icon-search"
  21. @click="handleSearch"
  22. >
  23. 搜索
  24. </el-button>
  25. </div>
  26. <el-button class="add-btn" type="primary" size="small" @click="handleAdd">添加</el-button>
  27. </div>
  28. <el-table
  29. :data="tableData"
  30. tooltip-effect="dark"
  31. border
  32. v-loading="loading"
  33. style="width: 100%"
  34. >
  35. <el-table-column
  36. align="center"
  37. label="用户ID"
  38. prop="publishUserId"
  39. show-overflow-tooltip
  40. >
  41. </el-table-column>
  42. <el-table-column
  43. prop="nickname"
  44. align="center"
  45. label="昵称"
  46. show-overflow-tooltip
  47. >
  48. </el-table-column>
  49. <el-table-column
  50. prop="createTime"
  51. align="center"
  52. label="创建时间"
  53. show-overflow-tooltip
  54. >
  55. </el-table-column>
  56. <el-table-column
  57. prop="communityTitle"
  58. align="center"
  59. label="标题"
  60. show-overflow-tooltip
  61. >
  62. </el-table-column>
  63. <el-table-column
  64. prop="viewedCount"
  65. align="center"
  66. label="浏览数"
  67. show-overflow-tooltip
  68. >
  69. </el-table-column>
  70. <!-- <el-table-column
  71. prop="payAmount"
  72. align="center"
  73. label="评论数"
  74. show-overflow-tooltip
  75. >
  76. </el-table-column> -->
  77. <el-table-column
  78. prop="likeCount"
  79. align="center"
  80. label="点赞数"
  81. show-overflow-tooltip
  82. >
  83. </el-table-column>
  84. <el-table-column
  85. prop="createTime"
  86. align="center"
  87. label="状态"
  88. show-overflow-tooltip
  89. >
  90. <template slot-scope="scope">
  91. <span :class="[scope.row.state == 1?'red':'green']">{{scope.row.state == 1?'隐藏':'显示' }}</span>
  92. </template>
  93. </el-table-column>
  94. <el-table-column prop="address" align="center" label="操作">
  95. <template slot-scope="scope">
  96. <el-button type="text" size="small" @click="handleDetail(scope.row)">编辑</el-button>
  97. <el-button type="text" size="small" @click="handleTop(scope.row.id)">置顶</el-button>
  98. <el-button type="text" size="small" @click="handleState(scope.row.id,scope.row.state == 1?2:1)">{{scope.row.state == 1?'显示':'隐藏' }}</el-button>
  99. <el-button type="text" class="red" size="small" @click="handleDel(scope.row.id)">删除</el-button>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <div class="page-box">
  104. <el-pagination
  105. @size-change="handleSizeChange"
  106. @current-change="handleCurrentChange"
  107. background
  108. :current-page="query.currentPage"
  109. :page-sizes="[10, 20, 30, 40]"
  110. :page-size="query.pageSize"
  111. layout="total, sizes, prev, pager, next, jumper"
  112. :total="total"
  113. >
  114. </el-pagination>
  115. </div>
  116. </div>
  117. </template>
  118. <script>
  119. import {debounce} from '@/utils/index'
  120. import {getCommunityList,operate,delCommunity,top} from '@/api/study'
  121. export default {
  122. name: "communityManage",
  123. data() {
  124. return {
  125. date:'',//时间
  126. tableData: [],
  127. loading: false,
  128. query: {
  129. "currentPage": 1,
  130. "pageSize": 10,
  131. "startDate":'',
  132. "endDate":'',
  133. },
  134. title: "",
  135. total: 0,
  136. };
  137. },
  138. watch: {
  139. // query: {
  140. // handler: debounce(function(val) {
  141. // this.getCommunityList()
  142. // }),
  143. // deep:true
  144. // },
  145. date(val){
  146. if(val){
  147. this.query.startDate = val[0]
  148. this.query.endDate = val[1]
  149. }else{
  150. this.query.startDate = ''
  151. this.query.endDate = ''
  152. }
  153. }
  154. },
  155. methods: {
  156. handleSearch(){
  157. this.query.currentPage = 1
  158. this.getCommunityList();
  159. },
  160. handleAdd(){
  161. this.$router.push('/studyManage/communityManage/addArticle')
  162. },
  163. handleTop(id){
  164. this.$confirm(`此操作将置顶该数据, 是否继续?`, '提示', {
  165. confirmButtonText: '确定',
  166. cancelButtonText: '取消',
  167. type: 'warning'
  168. }).then(() => {
  169. top({id}).then(res=>{
  170. if(res.state == 'Success'){
  171. this.$notify({
  172. title: '成功',
  173. message: '操作成功',
  174. type: 'success'
  175. });
  176. this.search()
  177. }
  178. })
  179. })
  180. },
  181. handleState(id,state){
  182. let msg
  183. if(state == 2){
  184. msg = '显示'
  185. }else{
  186. msg = '隐藏'
  187. }
  188. this.$confirm(`此操作将${msg}该数据, 是否继续?`, '提示', {
  189. confirmButtonText: '确定',
  190. cancelButtonText: '取消',
  191. type: 'warning'
  192. }).then(() => {
  193. operate({id,state}).then(res=>{
  194. if(res.state == 'Success'){
  195. this.$notify({
  196. title: '成功',
  197. message: '操作成功',
  198. type: 'success'
  199. });
  200. this.getCommunityList()
  201. }
  202. })
  203. })
  204. },
  205. // 点击删除
  206. handleDel(id) {
  207. this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
  208. confirmButtonText: '确定',
  209. cancelButtonText: '取消',
  210. type: 'warning'
  211. }).then(() => {
  212. delCommunity({id}).then(res=>{
  213. if(res.state == 'Success'){
  214. this.$notify({
  215. title: '成功',
  216. message: '操作成功',
  217. type: 'success'
  218. });
  219. this.search()
  220. }
  221. })
  222. })
  223. },
  224. handleDetail(row){
  225. this.$router.push({
  226. path:'/studyManage/communityManage/addArticle',
  227. query:{
  228. id:row.id
  229. }
  230. })
  231. },
  232. handleSizeChange(val) {
  233. this.query.currentPage = 1;
  234. this.query.pageSize = val;
  235. this.getCommunityList()
  236. },
  237. handleCurrentChange(val) {
  238. this.query.currentPage = val;
  239. this.getCommunityList()
  240. },
  241. search() {
  242. this.query.currentPage = 1;
  243. this.getCommunityList()
  244. },
  245. getCommunityList(){
  246. this.loading = true
  247. getCommunityList(this.query).then(res=>{
  248. this.loading = false
  249. if(res.state == 'Success'){
  250. this.tableData = res.content.records
  251. this.total = res.content.total
  252. }
  253. })
  254. }
  255. },
  256. created() {
  257. this.getCommunityList()
  258. },
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. .communityManage {
  263. .search{
  264. display: flex;
  265. justify-content: space-between;
  266. align-items: center;
  267. }
  268. }
  269. </style>