articleList.vue 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs='crumbs'></bread-crumb>
  5. <el-button style="float:right;" type="primary" size="small" icon="el-icon-circle-plus-outline" @click="AddArticle()">添加文章</el-button>
  6. </div>
  7. <div class="app-container">
  8. <div style="margin-bottom: 10px">
  9. <el-row :gutter="24">
  10. <el-col :span="8">
  11. <el-input style="width: 300px" v-model="keyword" placeholder="请输入您需要搜索的内容"></el-input>
  12. <el-button type="primary" icon="el-icon-search" @click="changeKey()">搜索</el-button>
  13. </el-col>
  14. </el-row>
  15. </div>
  16. <div class="cell clearfix">
  17. <label class="title"><span class="name">标签</span>:</label>
  18. <div class="time">
  19. <ul class="">
  20. <li :class="0==tagType?'active':''" @click="selectsign(0)">全部</li>
  21. <li :class="item.id==tagType?'active':''" v-for="item in tagOptions" :key="item.id" @click="selectsign(item.id)">{{item.name}}</li>
  22. </ul>
  23. </div>
  24. </div>
  25. <div class="cell clearfix">
  26. <label class="title"><span class="name">状态:</span></label>
  27. <div class="time">
  28. <ul class="">
  29. <li :class="{ active: selecting_status == 0 }" @click="changeSelectingStatus(0)">全部</li>
  30. <li :class="{ active: selecting_status == 1 }" @click="changeSelectingStatus(1)">已发布</li>
  31. <li :class="{ active: selecting_status == 2 }" @click="changeSelectingStatus(2)">草稿箱</li>
  32. <li :class="{ active: selecting_status == 3 }" @click="changeSelectingStatus(3)">未通过</li>
  33. </ul>
  34. </div>
  35. </div>
  36. <div class="filter-container" style="margin-top: 10px;margin-left: 5px">
  37. <el-checkbox style="width: 30px" @change="changeCheck" v-model="checkAllStatus">全选</el-checkbox>
  38. <el-button size="small" icon="el-icon-delete" @click="openDeletearticles">批量删除</el-button>
  39. </div>
  40. <el-table ref="multipleTable" :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}" :data="articsData" border fit highlight-current-row style="width: 100%;margin-top: 10px;" @selection-change="handleSelectionChange">
  41. <el-table-column
  42. align="center"
  43. type="selection"
  44. width="55">
  45. </el-table-column>
  46. <el-table-column label="文章图片" align="center">
  47. <template slot-scope="scope">
  48. <div class="parent">
  49. <span class="text">已发布</span>
  50. <div class="triangle-topleft">
  51. </div>
  52. <img :src="memberAvatar(scope.row)" style="width:100%;height:100%">
  53. </div>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="文章标题" align="center">
  57. <template slot-scope="scope">
  58. {{scope.row.title}}
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="阅读量" align="center">
  62. <template slot-scope="scope">
  63. {{scope.row.real_read_num}}
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="评论数" align="center">
  67. <template slot-scope="scope">
  68. {{scope.row.comment_num}}
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="点赞数" align="center">
  72. <template slot-scope="scope">
  73. {{scope.row.star_num}}
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" align="center">
  77. <template slot-scope="scope">
  78. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  79. <el-button
  80. size="mini"
  81. type="primary"
  82. icon="el-icon-edit-outline"
  83. @click="$router.push('/articles/editArticle/'+scope.row.id)">
  84. </el-button>
  85. </el-tooltip>
  86. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  87. <el-button size="mini" type="danger" icon="el-icon-delete" @click="openDelete(scope.row,scope.$index)" ></el-button>
  88. </el-tooltip>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <el-pagination
  93. @size-change="handleSizeChange"
  94. @current-change="handleCurrentChange"
  95. :page-sizes="[10,20,50,100]"
  96. :page-size="10"
  97. background
  98. style="margin-top:20px;float: right"
  99. layout="total, sizes, prev, pager, next, jumper"
  100. :total="total">
  101. </el-pagination>
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import BreadCrumb from '../components/bread-crumb'
  107. import { GetAllArticles,openDelete} from '@/api/act/submitinfo'
  108. export default {
  109. name: 'commentList',
  110. components:{
  111. BreadCrumb
  112. },
  113. inject:['reload'],
  114. data(){
  115. return{
  116. crumbs: [
  117. { path: false, name: '文章管理' },
  118. { path: '/articles/articleList', name: '文章列表' }
  119. ],
  120. time: '',
  121. active: true,
  122. tagType: 0,
  123. tagOptions:[],
  124. listQuery:{
  125. page:1,
  126. limit:10,
  127. classid:'',
  128. name:'',
  129. },
  130. articsData:[],
  131. total:0,
  132. selecting_status:'',
  133. keyword:'',
  134. dialogVisible: false,
  135. checkAllStatus:false,
  136. }
  137. },
  138. methods:{
  139. GetAllArticles(){
  140. GetAllArticles(this.listQuery,this.selecting_status,this.keyword,this.listQuery.classid).then(response=>{
  141. if(response.data.state === 1){
  142. this.articsData = response.data.data.articles
  143. this.total = response.data.data.total
  144. console.log("文章列表",this.articsData)
  145. console.log("total",this.total)
  146. }
  147. if(typeof(response.data.data.category != 'undefined')){
  148. this.tagOptions = response.data.data.category
  149. console.log("分类列表",this.tagOptions)
  150. }
  151. })
  152. },
  153. selectsign(id){
  154. console.log("id",id)
  155. this.listQuery.classid = id;
  156. this.listQuery.name = name;
  157. this.tagType = id;
  158. this.GetAllArticles();
  159. },
  160. handleSizeChange(limit) {
  161. this.listQuery.limit = limit;
  162. this.GetAllAritcles();
  163. },
  164. handleCurrentChange(page) {
  165. this.listQuery.page = page;
  166. this.GetAllAritcles();
  167. },
  168. changeKey(){
  169. this.GetAllArticles();
  170. },
  171. memberAvatar(row){
  172. return row.imgs
  173. },
  174. AddArticle(){
  175. this.$router.push({path:'/articles/createArticle'})
  176. },
  177. changeSelectingStatus(status){
  178. this.selecting_status = status;
  179. this.GetAllArticles();
  180. },
  181. openDelete(row,index){
  182. var id = row.id;
  183. this.$confirm('确认要删除该信息吗?删除后将无法恢复!',{
  184. dangerouslyUseHTMLString:true,
  185. confirmButtonText: '确定',
  186. cancelButtonText: '取消',
  187. type: 'warning'
  188. }).then(()=>{
  189. var ids = [];
  190. ids.push(row.id);
  191. openDelete({ids:ids}).then(response=>{
  192. this.articsData.splice(index,1);
  193. this.$message.success("删除成功");
  194. }).catch(e=>{});
  195. }).catch(e=>{});
  196. },
  197. handleSelectionChange(val){
  198. this.selectedArticles = val;
  199. },
  200. changeCheck(){
  201. this.$refs.multipleTable.clearSelection();
  202. if (this.checkAllStatus) {
  203. this.$refs.multipleTable.toggleAllSelection();
  204. }
  205. },
  206. openDeletearticles(){
  207. if (this.selectedArticles.length==0) {
  208. this.$message.error("请选择要删除的信息");
  209. return false;
  210. }
  211. this.$confirm('确定要删除吗?删除后信息将无法恢复!','删除提示',{
  212. dangerouslyUseHTMLString:true,
  213. confirmButtonText: '确定',
  214. cancelButtonText: '取消',
  215. type: 'warning'
  216. }).then(()=>{
  217. var ids = [];
  218. var idMap = {};
  219. for (const index in this.selectedArticles) {
  220. ids.push(this.selectedArticles[index].id);
  221. idMap[this.selectedArticles[index].id] = this.selectedArticles[index].id;
  222. }
  223. openDelete({ids:ids}).then(response=>{
  224. if(response.data.state == 1){
  225. var articsDatalength = this.articsData.length;
  226. for (let index = articsDatalength-1; index >= 0; index--) {
  227. if(this.articsData[index].id in idMap) {
  228. this.articsData.splice(index, 1);
  229. }
  230. }
  231. this.$message.success("删除成功");
  232. }else{
  233. this.$message.success("删除失败");
  234. }
  235. }).catch(e=>{});
  236. }).catch(() => {
  237. return false
  238. });
  239. }
  240. },
  241. created(){
  242. this.GetAllArticles()
  243. }
  244. }
  245. </script>
  246. <style scoped>
  247. .parent{
  248. position: relative;
  249. width: 160px;
  250. height: 120px;
  251. left: 20px;
  252. }
  253. .parent .text{
  254. display: inline-block;
  255. transform: rotate(-45deg);
  256. padding: 20px;
  257. color:red;
  258. position: relative;
  259. left: -60px;
  260. }
  261. .triangle-topleft{
  262. width: 0;
  263. height: 0;
  264. border-top: 70px solid yellow;
  265. border-right: 70px solid transparent;
  266. position: relative;
  267. margin-top: -140px;
  268. }
  269. </style>