acticleCategory.vue 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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="openCreate()">添加分类</el-button>
  6. </div>
  7. <div class="app-container">
  8. <div class="filter-container" style="margin-top: 10px;margin-left: 5px">
  9. <el-checkbox style="width: 30px" @change="changeCheck" v-model="checkAllStatus">全选</el-checkbox>
  10. <el-button size="small" icon="el-icon-delete" @click="openDeleteCategorys">批量删除</el-button>
  11. </div>
  12. <el-row :gutter="12" style="margin-top: 10px">
  13. <el-table
  14. border
  15. highlight-current-row
  16. ref="multipleTable"
  17. :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}"
  18. :data="articsData"
  19. @selection-change="handleSelectionChange"
  20. >
  21. <el-table-column
  22. type="selection"
  23. width="55">
  24. </el-table-column>
  25. <el-table-column label="分类名称" align="center">
  26. <template slot-scope="scope">
  27. {{scope.row.name}}
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="所属文章数量" align="center">
  31. <template slot-scope="scope">
  32. {{scope.row.num}}
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="分类排序" align="center">
  36. <template slot-scope="scope">
  37. {{scope.row.order}}
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="操作" align="center">
  41. <template slot-scope="scope">
  42. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  43. <el-button
  44. size="mini"
  45. type="primary"
  46. icon="el-icon-edit-outline"
  47. @click="openEdit(scope.row,scope.$index)">
  48. </el-button>
  49. </el-tooltip>
  50. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  51. <el-button
  52. size="mini"
  53. type="danger"
  54. icon="el-icon-delete"
  55. @click="openDelete(scope.row,scope.$index)">
  56. </el-button>
  57. </el-tooltip>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. <el-pagination
  62. @size-change="handleSizeChange"
  63. @current-change="handleCurrentChange"
  64. :page-sizes="[10,20,50,100]"
  65. :page-size="10"
  66. background
  67. style="margin-top:20px;"
  68. align="right"
  69. layout="total, sizes, prev, pager, next, jumper"
  70. :total="total">
  71. </el-pagination>
  72. <!-- 添加分类 -->
  73. <create-article-form ref="createArticleForm" :articsData="articsData"></create-article-form>
  74. <!-- 编辑分类 -->
  75. <edit-article-form ref="editArticleForm" :artilceIndex="artilceIndex" :form="articData" :articsData="articsData" ></edit-article-form>
  76. </el-row>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import BreadCrumb from '../components/bread-crumb'
  82. import CreateArticleForm from "./components/CreateArticleForm";
  83. import EditArticleForm from "./components/EditArticleForm";
  84. import { GetCategorys,DeleteCategorys } from '@/api/act/submitinfo';
  85. export default {
  86. name: 'acticleCategory',
  87. components:{
  88. BreadCrumb,
  89. CreateArticleForm,
  90. EditArticleForm,
  91. },
  92. data(){
  93. return{
  94. crumbs: [
  95. { path: false, name: '文章管理' },
  96. { path: '/articles/acticleCategory', name: '发布文章' }
  97. ],
  98. articsData:[],
  99. articData:{
  100. name:'',
  101. summary:'',
  102. order:'',
  103. id:0,
  104. },
  105. total:0,
  106. listQuery:{
  107. page:1,
  108. limit:10,
  109. name:'',
  110. summary:'',
  111. order:'',
  112. },
  113. artilceIndex:0,
  114. checkAllStatus:false,
  115. }
  116. },
  117. methods:{
  118. openCreate(){
  119. this.$refs.createArticleForm.open();
  120. },
  121. GetCategorys(){
  122. GetCategorys(this.listQuery).then(response=>{
  123. console.log(response.data.state)
  124. if(response.data.state === 1){
  125. this.articsData = response.data.data.category
  126. console.log(this.articsData)
  127. this.total = response.data.data.total
  128. }
  129. })
  130. },
  131. handleSizeChange(limit) {
  132. this.listQuery.limit = limit;
  133. this.GetCategorys();
  134. },
  135. handleCurrentChange(page) {
  136. this.listQuery.page = page;
  137. this.GetCategorys();
  138. },
  139. openEdit(row,index){
  140. for(const key in this.articData){
  141. if(key in row){
  142. this.articData[key] = row[key]
  143. }
  144. }
  145. console.log("是什么",this.articData)
  146. console.log("heh",this.articsData)
  147. this.artilceIndex = index
  148. this.$refs.editArticleForm.open();
  149. },
  150. changeCheck(){
  151. this.$refs.multipleTable.clearSelection();
  152. if (this.checkAllStatus) {
  153. this.$refs.multipleTable.toggleAllSelection();
  154. }
  155. },
  156. openDelete(row,index){
  157. this.$confirm('确认要删除该分类名称吗?<br>删除后,该分类名称信息将无法恢复',{
  158. dangerouslyUseHTMLString:true,
  159. confirmButtonText: '确定',
  160. cancelButtonText: '取消',
  161. type: 'warning'
  162. }).then(()=>{
  163. var ids = [];
  164. ids.push(row.id);
  165. DeleteCategorys({ids:ids}).then(response=>{
  166. var res = response.data;
  167. if(res.state === 1){
  168. this.articsData.splice(index,1);
  169. this.$message.success("删除会员成功");
  170. }else{
  171. this.$message.error(res.msg);
  172. }
  173. }).catch(e=>{});
  174. }).catch(() => {
  175. return false
  176. });
  177. },
  178. handleSelectionChange(val){
  179. this.selectedMembers = val;
  180. },
  181. openDeleteCategorys(){
  182. if (this.selectedMembers.length==0) {
  183. this.$message.error("请选择要删除的会员");
  184. return false;
  185. }
  186. this.$confirm('确认要删除所选的分类名称吗?<br>删除后,分类名称信息将无法恢复', '删除提示',{
  187. dangerouslyUseHTMLString:true,
  188. confirmButtonText: '确定',
  189. cancelButtonText: '取消',
  190. type: 'warning'
  191. }).then(()=>{
  192. var ids = [];
  193. var idMap = {};
  194. for (const index in this.selectedMembers) {
  195. ids.push(this.selectedMembers[index].id);
  196. idMap[this.selectedMembers[index].id] = this.selectedMembers[index].id;
  197. }
  198. DeleteCategorys({ids:ids}).then(response=>{
  199. var res = response.data;
  200. if(res.state ===1){
  201. var articsDatalength = this.articsData.length;
  202. for (let index = articsDatalength-1; index >= 0; index--) {
  203. if(this.articsData[index].id in idMap) {
  204. this.articsData.splice(index, 1);
  205. }
  206. }
  207. this.$message.success("删除会员成功");
  208. }else{
  209. this.$message.error(res.msg);
  210. }
  211. }).catch(e=>{});
  212. }).catch(() => {
  213. return false
  214. });
  215. },
  216. },
  217. created(){
  218. this.GetCategorys()
  219. }
  220. }
  221. </script>
  222. <style scoped>
  223. </style>