index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="6" class="left">
  6. <el-col :span="24" class="top">
  7. <el-col :span="18" class="title">
  8. 栏目信息
  9. </el-col>
  10. <el-col :span="6" class="btn">
  11. <el-button type="primary" size="mini" @click="dialog = true">添加栏目</el-button>
  12. </el-col>
  13. </el-col>
  14. <el-col :span="24" class="down">
  15. <data-table
  16. :fields="fields"
  17. :opera="opera"
  18. :data="columnList"
  19. :usePage="false"
  20. @query="search"
  21. @views="toViews"
  22. @edit="toEdit"
  23. @delete="toDelete"
  24. ></data-table>
  25. </el-col>
  26. </el-col>
  27. <el-col :span="18" class="right">
  28. <el-col :span="24" class="top">
  29. <el-col :span="18" class="title">
  30. 新闻信息
  31. </el-col>
  32. <el-col :span="6" class="btn">
  33. <el-button type="primary" size="mini" @click="$router.push({ path: '/news/detail' })">添加信息</el-button>
  34. </el-col>
  35. </el-col>
  36. <el-col :span="24" class="down">
  37. <data-table
  38. :fields="newsfields"
  39. :opera="newsopera"
  40. :data="list"
  41. :total="total"
  42. @query="newsSearch"
  43. @edit="newsEdit"
  44. @delete="newsDelete"
  45. ></data-table>
  46. </el-col>
  47. </el-col>
  48. </el-col>
  49. </el-row>
  50. <el-dialog title="栏目信息管理" width="40%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
  51. <data-form :data="form" :fields="fields" :rules="{}" @save="toSave">
  52. <template #options="{item}">
  53. <template v-if="item.model === 'site'">
  54. <el-option v-for="(i, index) in siteList" :key="index" :label="i.name" :value="i.site"></el-option>
  55. </template>
  56. </template>
  57. </data-form>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import dataTable from '@common/src/components/frame/filter-page-table.vue';
  63. import dataForm from '@common/src/components/frame/form.vue';
  64. import { mapState, createNamespacedHelpers } from 'vuex';
  65. const { mapActions: column } = createNamespacedHelpers('column');
  66. const { mapActions: news } = createNamespacedHelpers('news');
  67. export default {
  68. metaInfo() {
  69. return { title: this.$route.meta.title };
  70. },
  71. name: 'index',
  72. props: {},
  73. components: { dataTable, dataForm },
  74. data: function() {
  75. return {
  76. // 栏目列表
  77. opera: [
  78. {
  79. label: '查看信息',
  80. method: 'views',
  81. },
  82. {
  83. label: '编辑',
  84. method: 'edit',
  85. },
  86. {
  87. label: '删除',
  88. method: 'delete',
  89. },
  90. ],
  91. fields: [
  92. { label: '栏目名称', prop: 'name', model: 'name' },
  93. { label: '栏目位置', prop: 'site', model: 'site', type: 'select' },
  94. ],
  95. columnList: [],
  96. dialog: false,
  97. form: {},
  98. // 位置信息
  99. siteList: [
  100. { name: '问卷调查', site: 'wjdc' },
  101. { name: '行业研究', site: 'hyyj' },
  102. { name: '科技咨讯', site: 'kjzx' },
  103. { name: '工作动态', site: 'gzdt' },
  104. { name: '通知通告', site: 'tgtg' },
  105. { name: '技术前沿', site: 'jsqy' },
  106. { name: '政策解读', site: 'zcjd' },
  107. { name: '科技培训', site: 'kjpx' },
  108. { name: '科研动态', site: 'kydt' },
  109. { name: '学术交流', site: 'xsjl' },
  110. { name: '院地合作', site: 'ydhz' },
  111. { name: '热点事件', site: 'rdsj' },
  112. { name: '省内动态', site: 'sndt' },
  113. ],
  114. // 信息列表
  115. newsopera: [
  116. {
  117. label: '编辑',
  118. method: 'edit',
  119. },
  120. {
  121. label: '删除',
  122. method: 'delete',
  123. },
  124. ],
  125. newsfields: [
  126. { label: '所属栏目', prop: 'column_name' },
  127. { label: '信息标题', prop: 'title' },
  128. { label: '信息来源', prop: 'origin' },
  129. { label: '发布时间', prop: 'publish_time' },
  130. ],
  131. list: [],
  132. total: 0,
  133. };
  134. },
  135. async created() {
  136. await this.search();
  137. await this.newsSearch();
  138. },
  139. methods: {
  140. ...column({ columnQuery: 'query', columnFetch: 'fetch', columnCreate: 'create', columnUpdate: 'update', columnDelete: 'delete' }),
  141. ...news(['query', 'fetch', 'create', 'update', 'delete']),
  142. // 查询栏目数据
  143. async search({ skip = 0, limit = 10, ...info } = {}) {
  144. let res = await this.columnQuery({ skip, ...info });
  145. if (this.$checkRes(res)) {
  146. this.$set(this, `columnList`, res.data);
  147. }
  148. },
  149. // 修改栏目数据
  150. toEdit({ data }) {
  151. this.$set(this, `form`, data);
  152. this.dialog = true;
  153. },
  154. // 删除栏目数据
  155. async toDelete({ data }) {
  156. let res = await this.columnDelete(data.id);
  157. if (this.$checkRes(res)) {
  158. this.$message({
  159. message: '信息删除成功',
  160. type: 'success',
  161. });
  162. this.search();
  163. }
  164. },
  165. // 保存栏目数据
  166. async toSave({ data }) {
  167. if (data.id) {
  168. let res = await this.columnUpdate(data);
  169. if (this.$checkRes(res)) {
  170. this.$message({
  171. message: '信息修改成功',
  172. type: 'success',
  173. });
  174. this.handleClose();
  175. }
  176. } else {
  177. let res = await this.columnCreate(data);
  178. if (this.$checkRes(res)) {
  179. this.$message({
  180. message: '信息创建成功',
  181. type: 'success',
  182. });
  183. this.handleClose();
  184. }
  185. }
  186. },
  187. // 取消栏目数据
  188. handleClose() {
  189. this.form = {};
  190. this.dialog = false;
  191. this.search();
  192. },
  193. // 查看信息
  194. toViews({ data }) {
  195. this.newsSearch({ column_id: data.id });
  196. },
  197. // 新闻信息列表
  198. async newsSearch({ skip = 0, limit = 10, column_id, ...info } = {}) {
  199. if (column_id) info.column_id = column_id;
  200. let res = await this.query({ skip, limit, ...info });
  201. if (this.$checkRes(res)) {
  202. this.$set(this, `list`, res.data);
  203. this.$set(this, `total`, res.total);
  204. }
  205. },
  206. // 修改
  207. newsEdit({ data }) {
  208. this.$router.push({ path: '/news/detail', query: { id: data.id } });
  209. },
  210. // 删除
  211. async newsDelete({ data }) {
  212. let res = await this.delete(data.id);
  213. if (this.$checkRes(res)) {
  214. this.$message({
  215. message: '信息删除成功',
  216. type: 'success',
  217. });
  218. this.newsSearch();
  219. }
  220. },
  221. },
  222. computed: {
  223. ...mapState(['user']),
  224. },
  225. watch: {},
  226. };
  227. </script>
  228. <style lang="less" scoped>
  229. .main {
  230. .left {
  231. border: 1px solid #ccc;
  232. .top {
  233. height: 50px;
  234. padding: 10px;
  235. border-bottom: 1px solid #ccc;
  236. .title {
  237. padding: 2px 0;
  238. font-size: 18px;
  239. font-weight: bold;
  240. }
  241. .btn {
  242. text-align: right;
  243. }
  244. }
  245. .down {
  246. min-height: 670px;
  247. }
  248. }
  249. .right {
  250. border: 1px solid #ccc;
  251. .top {
  252. height: 50px;
  253. padding: 10px;
  254. border-bottom: 1px solid #ccc;
  255. .title {
  256. padding: 2px 0;
  257. font-size: 18px;
  258. font-weight: bold;
  259. }
  260. .btn {
  261. text-align: right;
  262. }
  263. }
  264. .down {
  265. min-height: 670px;
  266. }
  267. }
  268. }
  269. </style>