Sfoglia il codice sorgente

添加投稿管理

asd123a20 3 anni fa
parent
commit
36b8658d3f

+ 3 - 0
admin-contribution/.browserslistrc

@@ -0,0 +1,3 @@
+> 1%
+last 2 versions
+not dead

+ 5 - 0
admin-contribution/.editorconfig

@@ -0,0 +1,5 @@
+[*.{js,jsx,ts,tsx,vue}]
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true

+ 2 - 0
admin-contribution/.env

@@ -0,0 +1,2 @@
+# 窗口使用弹出还是抽屉 (dialog And drawer)
+VUE_APP_WINDOW=dialog

+ 1 - 0
admin-contribution/.eslintignore

@@ -0,0 +1 @@
+public-path.js

+ 23 - 0
admin-contribution/.eslintrc.js

@@ -0,0 +1,23 @@
+module.exports = {
+  root: true,
+  env: {
+    node: true
+  },
+  extends: [
+    'plugin:vue/essential',
+    '@vue/standard'
+  ],
+  parserOptions: {
+    parser: 'babel-eslint'
+  },
+  rules: {
+    'no-console': 0,
+    'no-debugger': 0,
+    'comma-dangle': [2, 'never'],
+    'no-extra-parens': 2,
+    'no-extra-semi': 2,
+    semi: [2, 'always'],
+    'space-before-function-paren': [0, 'always'],
+    eqeqeq: 0
+  }
+};

+ 23 - 0
admin-contribution/.gitignore

@@ -0,0 +1,23 @@
+.DS_Store
+node_modules
+/dist
+
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 24 - 0
admin-contribution/README.md

@@ -0,0 +1,24 @@
+# admin-role
+
+## Project setup
+```
+npm install
+```
+
+### Compiles and hot-reloads for development
+```
+npm run serve
+```
+
+### Compiles and minifies for production
+```
+npm run build
+```
+
+### Lints and fixes files
+```
+npm run lint
+```
+
+### Customize configuration
+See [Configuration Reference](https://cli.vuejs.org/config/).

+ 5 - 0
admin-contribution/babel.config.js

@@ -0,0 +1,5 @@
+module.exports = {
+  presets: [
+    '@vue/cli-plugin-babel/preset'
+  ]
+};

File diff suppressed because it is too large
+ 12565 - 0
admin-contribution/package-lock.json


+ 35 - 0
admin-contribution/package.json

@@ -0,0 +1,35 @@
+{
+  "name": "admin-contents",
+  "version": "0.1.0",
+  "private": true,
+  "scripts": {
+    "serve": "vue-cli-service serve",
+    "build": "vue-cli-service build",
+    "lint": "vue-cli-service lint"
+  },
+  "dependencies": {
+    "core-js": "^3.6.5",
+    "element-ui": "^2.15.6",
+    "sass": "^1.48.0",
+    "sass-loader": "^10.0.0",
+    "vue": "^2.6.11",
+    "vue-router": "^3.2.0",
+    "vuex": "^3.4.0"
+  },
+  "devDependencies": {
+    "@vue/cli-plugin-babel": "~4.5.0",
+    "@vue/cli-plugin-eslint": "~4.5.0",
+    "@vue/cli-plugin-router": "~4.5.0",
+    "@vue/cli-plugin-vuex": "~4.5.0",
+    "@vue/cli-service": "~4.5.0",
+    "@vue/eslint-config-standard": "^5.1.2",
+    "babel-eslint": "^10.1.0",
+    "eslint": "^6.7.2",
+    "eslint-plugin-import": "^2.20.2",
+    "eslint-plugin-node": "^11.1.0",
+    "eslint-plugin-promise": "^4.2.1",
+    "eslint-plugin-standard": "^4.0.0",
+    "eslint-plugin-vue": "^6.2.2",
+    "vue-template-compiler": "^2.6.11"
+  }
+}

BIN
admin-contribution/public/favicon.ico


+ 17 - 0
admin-contribution/public/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width,initial-scale=1.0">
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
+    <title><%= htmlWebpackPlugin.options.title %></title>
+  </head>
+  <body>
+    <noscript>
+      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
+    </noscript>
+    <div id="app"></div>
+    <!-- built files will be auto injected -->
+  </body>
+</html>

+ 24 - 0
admin-contribution/src/App.vue

@@ -0,0 +1,24 @@
+<template>
+  <div id="app">
+    <router-view></router-view>
+  </div>
+</template>
+
+<script>
+export default {
+  components: {},
+  computed: {},
+  data() {
+    return {};
+  },
+  mounted() {},
+  methods: {}
+};
+</script>
+
+<style lang="scss" scoped>
+#app {
+  width: 100%;
+  height: 100%;
+}
+</style>

BIN
admin-contribution/src/assets/logo.png


+ 48 - 0
admin-contribution/src/main.js

@@ -0,0 +1,48 @@
+import Vue from 'vue';
+import App from './App.vue';
+import VueRouter from 'vue-router';
+import routes from './router';
+import store from './store';
+import ElementUI from 'element-ui';
+import 'element-ui/lib/theme-chalk/index.css';
+import './public-path.js';
+import dict from '@lib/dict.js';
+import tree from '@lib/tree.js';
+import resChange from '@lib/resChange.js';
+Vue.config.productionTip = false;
+Vue.use(VueRouter);
+Vue.use(ElementUI);
+Vue.use(dict);
+Vue.use(tree);
+Vue.use(resChange);
+let router = null;
+let instance = null;
+function render (props = {}) {
+  const { container } = props;
+  router = new VueRouter({
+    base: window.__POWERED_BY_QIANKUN__ ? '/admin/contribution/' : '/',
+    mode: 'history',
+    routes
+  });
+  instance = new Vue({
+    router,
+    store,
+    render: (h) => h(App)
+  }).$mount(container ? container.querySelector('#app') : '#app');
+}
+
+// 独立运行时
+if (!window.__POWERED_BY_QIANKUN__) {
+  render();
+}
+
+export async function bootstrap () {}
+export async function mount (props) {
+  render(props);
+}
+export async function unmount () {
+  instance.$destroy();
+  instance.$el.innerHTML = '';
+  instance = null;
+  router = null;
+}

+ 3 - 0
admin-contribution/src/public-path.js

@@ -0,0 +1,3 @@
+if (window.__POWERED_BY_QIANKUN__) {
+  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
+}

+ 11 - 0
admin-contribution/src/router/index.js

@@ -0,0 +1,11 @@
+import home from '../views/home.vue';
+
+const routes = [
+  {
+    path: '/home',
+    name: 'home',
+    component: home
+  }
+];
+
+export default routes;

+ 64 - 0
admin-contribution/src/store/index.js

@@ -0,0 +1,64 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import $axios from '@lib/axios.js';
+const api = {
+  contributionCreate: '/api/contribution/draft/create',
+  contributionUpdate: '/api/contribution/draft/update',
+  contributionDelete: '/api/contribution/draft/delete',
+  contributionQuery: '/api/contribution/draft/query',
+  contributionFetch: '/api/contribution/draft/fetch',
+  dictQuery: '/api/code/dictionary/query'
+};
+Vue.use(Vuex);
+const state = () => ({
+  Total: 0,
+  contributionList: [],
+  columnList: [],
+  dict: {}
+});
+
+const actions = {
+  async contributionCreate ({ commit }, payload) {
+    const res = await $axios.post(api.contributionCreate, payload);
+    return res;
+  },
+  async contributionUpdate ({ commit }, payload) {
+    const res = await $axios.post(api.contributionUpdate, { ...payload, id: payload._id });
+    return res;
+  },
+  async contributionDelete ({ commit }, { id }) {
+    const res = await $axios.delete(`${api.contributionDelete}/${id}`);
+    return res;
+  },
+  async contributionQuery ({ commit }, { filter, paging } = {}) {
+    const res = await $axios.get(api.contributionQuery, { ...filter, skip: paging.page, limit: paging.size });
+    commit('contributionQuery', res);
+    return res;
+  },
+  async contributionFetch ({ commit }, payload) {
+    const res = await $axios.get(api.contributionFetch, payload);
+    return res;
+  },
+  async statusQuery ({ commit }) {
+    const res = await $axios.get(api.dictQuery, { parentCode: 'contributionStatus' });
+    commit('statusQuery', res);
+    return res;
+  }
+};
+
+const mutations = {
+  contributionQuery(state, payload) {
+    state.contributionList = payload.data;
+    state.Total = payload.total;
+  },
+  statusQuery(state, payload) {
+    state.dict.contributionStatus = payload.data;
+  }
+};
+
+export default new Vuex.Store({
+  state,
+  actions,
+  mutations,
+  modules: {}
+});

+ 192 - 0
admin-contribution/src/views/home.vue

@@ -0,0 +1,192 @@
+<template>
+  <div class="box">
+    <el-card class="box-card">
+      <div slot="header" class="clearfix">
+        <span>投稿管理</span>
+        <el-button style="float: right; padding: 3px 0" type="text" @click="addcontribution">添加投稿</el-button>
+      </div>
+      <div class="main">
+        <filterList ref="filterList" :tableData="contributionList" :filed="filed" @edit="filtereEdit" @delete="filterDelete" @query="filterQuery" :total="Total"></filterList>
+      </div>
+    </el-card>
+    <dialogAndDrawer :width="'35%'" :title="title" :visibleSync="visibleSync" v-if="visibleSync" @close="visibleSync = false">
+      <template v-slot:windowMain>
+        <formData ref="formData" :filed="formfiled" :data="formdata" :rules="formrules" @save="formSave" v-if="visibleSync">
+          <template v-slot:formItem="{ item }">
+            <!-- 附件上传 -->
+            <el-upload
+              v-if="item.name == 'url'"
+              :headers="myHeaders"
+              class="upload-demo"
+              action="/api/files/avatar/upload"
+              :on-success="handleAnnexSuccess"
+              :on-remove="handleRemove"
+              :file-list="fileList">
+              <el-button size="small" type="primary">附件上传</el-button>
+            </el-upload>
+          </template>
+        </formData>
+      </template>
+    </dialogAndDrawer>
+  </div>
+</template>
+<script>
+import filterList from '@components/filterList/index.vue';
+import dialogAndDrawer from '@components/dialogAndDrawer.vue';
+import formData from '@components/formData/index.vue';
+import { mapState, mapActions } from 'vuex';
+const token = sessionStorage.getItem('token');
+export default {
+  components: {
+    filterList,
+    dialogAndDrawer,
+    formData
+  },
+  data() {
+    return {
+      fileList: [],
+      myHeaders: { Authorization: token },
+      title: '',
+      visibleSync: false,
+      filed: [
+        { name: 'title', label: '标题', filter: true },
+        { name: 'name', label: '姓名', filter: true },
+        { name: 'phone', label: '电话' }
+      ],
+      formdata: {},
+      formfiled: [
+        { name: 'title', label: '标题' },
+        { name: 'name', label: '姓名' },
+        { name: 'phone', label: '电话' },
+        { name: 'workUnit', label: '单位' },
+        { name: 'address', label: '地址' },
+        { name: 'status', label: '状态', formater: 'dict:contributionStatus' },
+        { name: 'url', label: '附件', formater: 'slot' },
+        { name: 'openid', label: 'openid' }
+      ],
+      formrules: {
+        title: [
+          { required: true, message: '请输入标题', trigger: 'blur' }
+        ],
+        name: [
+          { required: true, message: '请输入姓名', trigger: 'blur' }
+        ],
+        phone: [
+          { required: true, message: '请输入手机号', trigger: 'chage' }
+        ],
+        workUnit: [
+          { required: true, message: '请输入单位', trigger: 'blur' }
+        ],
+        address: [
+          { required: true, message: '请输入地址', trigger: 'blur' }
+        ],
+        status: [
+          { required: true, message: '请选择状态', trigger: 'chage' }
+        ]
+      }
+    };
+  },
+  computed: {
+    ...mapState(['contributionList', 'Total'])
+  },
+  async created() {
+    await this.filterQuery();
+    await this.statusQuery();
+  },
+  methods: {
+    ...mapActions(['contributionQuery', 'contributionCreate', 'contributionUpdate', 'contributionDelete', 'contributionFetch', 'statusQuery']),
+    // 添加
+    addcontribution () {
+      this.formdata = {};
+      this.title = '添加投稿';
+      this.visibleSync = true;
+    },
+    // 修改
+    async filtereEdit (e) {
+      this.formdata = e;
+      this.title = '修改投稿';
+      this.visibleSync = true;
+    },
+    // 删除
+    async filterDelete (e) {
+      const res = await this.contributionDelete({ id: e?._id });
+      this.$resChange(res, '删除成功');
+      this.filterQuery();
+    },
+    // 查询
+    async filterQuery ({ filter = {}, paging = { content: 0, size: 10 } } = {}) {
+      await this.contributionQuery({ filter, paging });
+    },
+    // 表单保存
+    async formSave (e) {
+      if (e.isRevise && e?.isRevise == false) {
+        this.$message.warning('未作修改');
+        return;
+      }
+      this.$delete(e, 'isRevise');
+      let res, msg;
+      // 修改
+      if (e._id) {
+        res = await this.contributionUpdate(e);
+        msg = '投稿修改成功';
+      } else {
+        res = await this.contributionCreate(e);
+        msg = '投稿添加成功';
+      }
+      this.$resChange(res, msg);
+      this.filterQuery();
+      this.visibleSync = false;
+    },
+    // 附件上传
+    handleAnnexSuccess(res, file) {
+      this.$refs.formData.setForm('annex', res.data.filePath);
+      this.fileList.push({ name: res.data.name, url: res.data.filePath });
+    },
+    // 删除附件列表
+    handleRemove(file, fileList) {
+      console.log(123);
+      this.$refs.formData.setForm('annex', null);
+      delete this.fileList[0];
+    }
+  }
+};
+</script>
+<style lang="scss" scoped>
+.box {
+  width: 100%;
+  height: 100%;
+  .box-card {
+    height: 100%;
+    .el-card__body {
+      height: 100%;
+    }
+  }
+}
+.el-dialog {
+  .avatar-uploader-icon {
+    font-size: 28px;
+    color: #8c939d;
+    width: 120px;
+    height: 120px;
+    line-height: 120px;
+    text-align: center;
+  }
+  .avatar {
+    width: 120px;
+    height: 120px;
+    display: block;
+  }
+}
+</style>
+<style>
+.el-upload {
+  border: 1px dashed #d9d9d9;
+  border-radius: 6px;
+  cursor: pointer;
+  position: relative;
+  overflow: hidden;
+}
+.el-upload:hover {
+  border-color: #409EFF;
+}
+</style>

+ 33 - 0
admin-contribution/vue.config.js

@@ -0,0 +1,33 @@
+const path = require('path');
+const frameSrc = path.resolve(__dirname, '../admin-frame');
+const packageName = require('./package.json').name;
+module.exports = {
+  publicPath: `/${packageName}/`,
+  outputDir: path.join(frameSrc, `../../admin-web/${packageName}/`),
+  devServer: {
+    port: 3019,
+    headers: {
+      'Access-Control-Allow-Origin': '*'
+    },
+    proxy: {
+      '/api/': {
+        // target: 'http://192.168.0.45:18090'
+        target: 'http://192.168.3.45:18090'
+      }
+    }
+  },
+  configureWebpack: {
+    output: {
+      library: `${packageName}-[name]`,
+      libraryTarget: 'umd',
+      jsonpFunction: `webpackJsonp_${packageName}`
+    },
+    resolve: {
+      alias: {
+        '@components': path.join(frameSrc, '/src/components'),
+        '@style': path.join(frameSrc, '/style'),
+        '@lib': path.join(frameSrc, '/lib')
+      }
+    }
+  }
+};

+ 6 - 0
admin-frame/lib/apps.js

@@ -116,5 +116,11 @@ export default [
     entry: config.dev ? '//localhost:3018/admin-activity/' : 'admin-activity',
     container: config.tabs ? '#activity' : '#content',
     activeRule: '/admin/activity'
+  },
+  {
+    name: 'admin-contribution',
+    entry: config.dev ? '//localhost:3019/admin-contribution/' : 'admin-contribution',
+    container: config.tabs ? '#contribution' : '#content',
+    activeRule: '/admin/contribution'
   }
 ];

+ 3 - 0
xms.code-workspace

@@ -54,6 +54,9 @@
 		{
 			"path": "admin-activity"
 		},
+		{
+			"path": "admin-contribution"
+		},
 	],
 	"settings": {}
 }