NewsManager.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div>
  3. <div class="operation">
  4. <el-input v-model="search" placeholder="请输入新闻名称" size="mini"></el-input>
  5. <el-select v-model="status" size="mini">
  6. <el-option value="-1" label="全部"></el-option>
  7. <el-option value="1" label="启用"></el-option>
  8. <el-option value="0" label="禁用"></el-option>
  9. </el-select>
  10. <div class="btn">
  11. <el-button type="primary" @click="getItems" size="mini">查询</el-button>
  12. <el-button type="primary" @click="goAdd" size="mini">添加</el-button>
  13. </div>
  14. </div>
  15. <el-table :data="items">
  16. <el-table-column label="新闻ID" prop="id"></el-table-column>
  17. <el-table-column label="新闻图标" width="110px">
  18. 图标
  19. <template slot-scope="scope">
  20. <img :src="scope.row.icon" style="width:100px;" />
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="新闻名称" prop="name"></el-table-column>
  24. <el-table-column label="新闻标题" prop="describe"></el-table-column>
  25. <el-table-column label="发布时间" prop="time"></el-table-column>
  26. <el-table-column label="描述" prop="describe"></el-table-column>
  27. <el-table-column label="阅读数" prop="wacth"></el-table-column>
  28. <el-table-column label="状态">
  29. <template slot-scope="scope">
  30. <template v-if="scope.row.status === 1">
  31. <p class="online">启用</p>
  32. </template>
  33. <template v-else>
  34. <p class="offline">禁用</p>
  35. </template>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="推荐新闻">
  39. <template slot-scope="scope">
  40. <template v-if="scope.row.recommend">
  41. <p v-on:click="setRecommend(scope.row)" class="online">是</p>
  42. </template>
  43. <template v-else>
  44. <p v-on:click="setRecommend(scope.row)" class="offline">否</p>
  45. </template>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="操作" width="250px">
  49. <template slot-scope="scope">
  50. <template v-if="scope.row.status == 0">
  51. <el-button type="success" @click="setStatus(scope.row)" size="mini">启用</el-button>
  52. </template>
  53. <template v-else>
  54. <el-button type="danger" @click="setStatus(scope.row)" size="mini">禁用</el-button>
  55. </template>
  56. <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
  57. <el-button type="text" size="small" @click="goEditLabel(scope.row)">标签</el-button>
  58. <a :href="serverPath + 'new/detail/' + scope.row.id" target="_black">
  59. <el-button type="text" size="small">预览</el-button>
  60. </a>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <div class="page">
  65. <el-pagination
  66. background
  67. layout="total, prev, pager, next,jumper"
  68. @current-change="nextPage"
  69. :page-size="pageSize"
  70. :total="totalCount"
  71. ></el-pagination>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. page: 1,
  80. pageSize: 20,
  81. items: [],
  82. totalCount: 0,
  83. status: "-1",
  84. search: "",
  85. serverPath: process.env.SERVER_PATH
  86. };
  87. },
  88. methods: {
  89. getItems: function() {
  90. this.$http
  91. .getNews(
  92. {
  93. page: this.page,
  94. pageSize: this.pageSize,
  95. status: this.status,
  96. search: this.search
  97. },
  98. this
  99. )
  100. .then(data => {
  101. this.items = data.obj.list;
  102. this.totalCount = data.obj.totalCount;
  103. });
  104. },
  105. nextPage: function(currentPage) {
  106. this.page = currentPage;
  107. this.getItems();
  108. },
  109. statusFormater: function(row) {
  110. if (row.status === 1) {
  111. return "在线";
  112. } else {
  113. return "离线";
  114. }
  115. },
  116. setStatus: function(row) {
  117. let msg = row.status === 1 ? "禁用" : "启用";
  118. this.$confirm(
  119. '您确定要将此商品设置为 "' + msg + '" , 是否继续?',
  120. "提示",
  121. {
  122. confirmButtonText: "确定",
  123. cancelButtonText: "取消",
  124. type: "warning"
  125. }
  126. )
  127. .then(() => {
  128. this.$http
  129. .setNewStatus(
  130. { id: row.id, status: row.status === 1 ? false : true },
  131. this
  132. )
  133. .then(res => {
  134. if (res.code === 0) {
  135. row.status = row.status === 1 ? 0 : 1;
  136. this.$message({
  137. message: "操作成功",
  138. type: "success"
  139. });
  140. }
  141. });
  142. })
  143. .catch(() => {});
  144. },
  145. goEdit: function(row) {
  146. this.$router.push({ path: "/editNew", query: { id: row.id } });
  147. },
  148. goAdd: function(row) {
  149. this.$router.push({ path: "/editNew", query: { id: 0 } });
  150. },
  151. goEditLabel: function(row) {
  152. this.$router.push({ path: "/newTypeManage", query: { id: row.id } });
  153. },
  154. setRecommend: function(row) {
  155. var msg = row.recommend
  156. ? "您是否要停止推荐此新闻吗?"
  157. : "您是否要推荐此新闻?";
  158. this.$confirm(msg, "提示", {
  159. confirmButtonText: "确定",
  160. cancelButtonText: "取消",
  161. type: "warning"
  162. }).then(res => {
  163. this.$http
  164. .setNewRecommend(
  165. { id: row.id, recommend: row.recommend ? false : true },
  166. this
  167. )
  168. .then(res => {
  169. row.recommend = !row.recommend;
  170. });
  171. });
  172. }
  173. },
  174. mounted: function() {
  175. this.getItems();
  176. }
  177. };
  178. </script>
  179. <style scoped>
  180. .page {
  181. margin-top: 10px;
  182. }
  183. .online {
  184. color: #67c23a;
  185. }
  186. .offline {
  187. color: #f56c6c;
  188. }
  189. .operation {
  190. display: flex;
  191. height: 50px;
  192. border-bottom: 1px solid #e6e6e6;
  193. margin-bottom: 10px;
  194. }
  195. .operation .btn {
  196. display: flex;
  197. height: 28px;
  198. }
  199. .operation .btn,
  200. .operation .el-input,
  201. .operation .el-select {
  202. width: 150px;
  203. margin-right: 8px;
  204. }
  205. </style>