asd123a20 3 years ago
parent
commit
936c1688bc
29 changed files with 155 additions and 100 deletions
  1. 5 0
      app/controller/content.js
  2. 2 2
      app/model/Banner.js
  3. 14 6
      app/model/Content.js
  4. 2 2
      app/model/Page.js
  5. 65 65
      app/public/adminMenu.js
  6. BIN
      app/public/files/019fe8f0-e3cd-11eb-a574-71b27b775b3f.docx
  7. BIN
      app/public/files/08436f10-e3cd-11eb-a574-71b27b775b3f.docx
  8. BIN
      app/public/files/769a1240-e3d5-11eb-8937-e3d3c65aed8f.docx
  9. BIN
      app/public/files/93ad7610-e3d5-11eb-8937-e3d3c65aed8f.docx
  10. BIN
      app/public/files/b9059770-e3d6-11eb-8232-5fd805b3097f.docx
  11. BIN
      app/public/files/c32cc610-e3d6-11eb-8232-5fd805b3097f.docx
  12. BIN
      app/public/files/fbba0d80-e3cc-11eb-a574-71b27b775b3f.docx
  13. BIN
      app/public/resource/1750ee90-e43d-11eb-abea-7db7203356f5.jpeg
  14. BIN
      app/public/resource/3fffbad0-e3d7-11eb-90dd-dbe4e5298753.jpeg
  15. BIN
      app/public/resource/4597eb70-e3d7-11eb-90dd-dbe4e5298753.jpeg
  16. BIN
      app/public/resource/4a9b2f10-e3d7-11eb-90dd-dbe4e5298753.jpeg
  17. BIN
      app/public/resource/78b996e0-e3d5-11eb-8937-e3d3c65aed8f.jpeg
  18. BIN
      app/public/resource/8d09a1d0-e3d5-11eb-8937-e3d3c65aed8f.jpeg
  19. BIN
      app/public/resource/90b25e80-e3d5-11eb-8937-e3d3c65aed8f.jpeg
  20. BIN
      app/public/resource/b6543310-e3d6-11eb-8232-5fd805b3097f.jpeg
  21. BIN
      app/public/resource/c0bcd780-e3d6-11eb-8232-5fd805b3097f.jpeg
  22. BIN
      app/public/resource/debf0820-e3d6-11eb-8232-5fd805b3097f.jpeg
  23. BIN
      app/public/resource/f6659110-e3d6-11eb-8232-5fd805b3097f.jpeg
  24. 1 0
      app/router.js
  25. 10 6
      app/service/banner.js
  26. 34 9
      app/service/content.js
  27. 3 0
      app/service/files.js
  28. 14 6
      app/service/page.js
  29. 5 4
      config/config.default.js

+ 5 - 0
app/controller/content.js

@@ -28,6 +28,11 @@ class ContentController extends Controller {
     const res = await ctx.service.content.details(ctx.params);
     ctx.body = res;
   }
+  async filepath() {
+    const { ctx } = this;
+    const res = await ctx.service.content.filepath(ctx.params);
+    ctx.body = res;
+  }
 }
 
 module.exports = ContentController;

+ 2 - 2
app/model/Banner.js

@@ -7,8 +7,8 @@ module.exports = app => {
     title: {
       type: String,
     },
-    // 短标题
-    shortTitle: {
+    // 发表日期
+    date: {
       type: String,
     },
     // 摘要

+ 14 - 6
app/model/Content.js

@@ -7,10 +7,6 @@ module.exports = app => {
     title: {
       type: String,
     },
-    // 短标题
-    shortTitle: {
-      type: String,
-    },
     // 摘要
     slug: {
       type: String,
@@ -23,6 +19,7 @@ module.exports = app => {
     annex: {
       type: String,
     },
+    // 缩略图
     annexname: {
       type: String,
     },
@@ -43,15 +40,26 @@ module.exports = app => {
       type: String,
     },
     // 绑定栏目组
-    columnList: {
-      type: Array,
+    columns: {
+      type: String,
     },
+    // 文章年
     year: {
       type: String,
     },
+    // 文章日期
     date: {
       type: String,
     },
+    // 访问量
+    hits: {
+      type: Number,
+      default: 0,
+    },
+    // 第多少期
+    term: {
+      type: String,
+    },
   });
   return mongoose.model('Content', ContentSchema);
 };

+ 2 - 2
app/model/Page.js

@@ -7,8 +7,8 @@ module.exports = app => {
     title: {
       type: String,
     },
-    // 短标题
-    shortTitle: {
+    // 发表日期
+    date: {
       type: String,
     },
     // 摘要

+ 65 - 65
app/public/adminMenu.js

@@ -1,5 +1,69 @@
 'use strict';
 module.exports = [
+  {
+    title: '站点配置',
+    path: '/wokes/webconfig',
+    id: '2-3',
+    icons: 'el-icon-user-solid',
+    parentId: '2',
+    module: '@wokes',
+  },
+  {
+    title: '内容管理',
+    path: '3',
+    id: '3',
+    icons: 'el-icon-user-solid',
+    parentId: '',
+    module: '@wokes',
+  },
+  {
+    title: '菜单管理',
+    path: '/wokes/menu',
+    id: '3-1',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
+  {
+    title: '栏目管理',
+    path: '/wokes/column',
+    id: '3-2',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
+  {
+    title: '文章管理',
+    path: '/wokes/content',
+    id: '3-3',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
+  {
+    title: '单页管理',
+    path: '/wokes/pages',
+    id: '3-4',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
+  {
+    title: '文件管理',
+    path: '/wokes/files',
+    id: '3-5',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
+  {
+    title: '资源管理',
+    path: '/wokes/resource',
+    id: '3-6',
+    icons: 'el-icon-user-solid',
+    parentId: '3',
+    module: '@wokes',
+  },
   {
     title: '系统管理',
     path: '1',
@@ -49,7 +113,7 @@ module.exports = [
     module: '@gaf',
   },
   {
-    title: '系统配置',
+    title: '网站配置',
     path: '2',
     id: '2',
     icons: 'el-icon-user-solid',
@@ -72,68 +136,4 @@ module.exports = [
     parentId: '2',
     module: '@wokes',
   },
-  {
-    title: '站点配置',
-    path: '/wokes/webconfig',
-    id: '2-3',
-    icons: 'el-icon-user-solid',
-    parentId: '2',
-    module: '@wokes',
-  },
-  {
-    title: '内容管理',
-    path: '3',
-    id: '3',
-    icons: 'el-icon-user-solid',
-    parentId: '',
-    module: '@wokes',
-  },
-  {
-    title: '菜单管理',
-    path: '/wokes/menu',
-    id: '3-1',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
-  {
-    title: '栏目管理',
-    path: '/wokes/column',
-    id: '3-2',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
-  {
-    title: '文章管理',
-    path: '/wokes/content',
-    id: '3-3',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
-  {
-    title: '单页管理',
-    path: '/wokes/pages',
-    id: '3-4',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
-  {
-    title: '文件管理',
-    path: '/wokes/files',
-    id: '3-5',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
-  {
-    title: '资源管理',
-    path: '/wokes/resource',
-    id: '3-6',
-    icons: 'el-icon-user-solid',
-    parentId: '3',
-    module: '@wokes',
-  },
 ];

BIN
app/public/files/019fe8f0-e3cd-11eb-a574-71b27b775b3f.docx


BIN
app/public/files/08436f10-e3cd-11eb-a574-71b27b775b3f.docx


BIN
app/public/files/769a1240-e3d5-11eb-8937-e3d3c65aed8f.docx


BIN
app/public/files/93ad7610-e3d5-11eb-8937-e3d3c65aed8f.docx


BIN
app/public/files/b9059770-e3d6-11eb-8232-5fd805b3097f.docx


BIN
app/public/files/c32cc610-e3d6-11eb-8232-5fd805b3097f.docx


BIN
app/public/files/fbba0d80-e3cc-11eb-a574-71b27b775b3f.docx


BIN
app/public/resource/1750ee90-e43d-11eb-abea-7db7203356f5.jpeg


BIN
app/public/resource/3fffbad0-e3d7-11eb-90dd-dbe4e5298753.jpeg


BIN
app/public/resource/4597eb70-e3d7-11eb-90dd-dbe4e5298753.jpeg


BIN
app/public/resource/4a9b2f10-e3d7-11eb-90dd-dbe4e5298753.jpeg


BIN
app/public/resource/78b996e0-e3d5-11eb-8937-e3d3c65aed8f.jpeg


BIN
app/public/resource/8d09a1d0-e3d5-11eb-8937-e3d3c65aed8f.jpeg


BIN
app/public/resource/90b25e80-e3d5-11eb-8937-e3d3c65aed8f.jpeg


BIN
app/public/resource/b6543310-e3d6-11eb-8232-5fd805b3097f.jpeg


BIN
app/public/resource/c0bcd780-e3d6-11eb-8232-5fd805b3097f.jpeg


BIN
app/public/resource/debf0820-e3d6-11eb-8232-5fd805b3097f.jpeg


BIN
app/public/resource/f6659110-e3d6-11eb-8232-5fd805b3097f.jpeg


+ 1 - 0
app/router.js

@@ -37,6 +37,7 @@ module.exports = app => {
   router.delete('/api/content/delete/:id', jwt, controller.content.del);
   router.get('/api/content/query', controller.content.query);
   router.get('/api/content/details/:id', controller.content.details);
+  router.get('/api/content/filepath', controller.content.filepath);
   // 单页
   router.post('/api/page/create', jwt, controller.page.create);
   router.post('/api/page/update', jwt, controller.page.update);

+ 10 - 6
app/service/banner.js

@@ -4,27 +4,31 @@ const Service = require('egg').Service;
 const assert = require('assert');
 const moment = require('moment');
 class ContentService extends Service {
-  async create({ title, shortTitle, slug, path, annex, content, annexname }) {
+  async create({ title, path, annex, content, annexname, date }) {
     assert(title, '标题不存在');
-    assert(shortTitle, '短标题不存在');
-    assert(slug, '摘要不存在');
     assert(path, '轮播图不存在');
     assert(content, '内容不存在');
     const { Banner: model } = this.ctx.model;
     const createAt = moment().format('x');
     try {
-      await model.create({ title, shortTitle, slug, path, annex, content, createAt, annexname });
+      let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+      text = text.replace('\\s*|\t|\r|\n', '');
+      const slug = text.substring(0, 200);
+      await model.create({ title, date, slug, path, annex, content, createAt, annexname });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       console.log(error);
       throw new Error({ errcode: -2001, errmsg: '添加失败' });
     }
   }
-  async update({ title, shortTitle, slug, path, annex, content, istop, _id, annexname }) {
+  async update({ title, path, annex, content, date, _id, annexname }) {
     assert(_id, 'id不存在');
     const { Banner: model } = this.ctx.model;
     try {
-      await model.findById(_id).update({ title, shortTitle, slug, path, annex, content, istop, annexname });
+      let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+      text = text.replace('\\s*|\t|\r|\n', '');
+      const slug = text.substring(0, 200);
+      await model.findById(_id).update({ title, slug, path, annex, date, content, annexname });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '修改失败' });

+ 34 - 9
app/service/content.js

@@ -4,26 +4,31 @@ const Service = require('egg').Service;
 const assert = require('assert');
 const moment = require('moment');
 class ContentService extends Service {
-  async create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, year, datte, annexname }) {
+  async create({ title, thumbnail, annex, content, istop, columns, date, annexname, term }) {
     assert(title, '标题不存在');
-    assert(shortTitle, '短标题不存在');
-    assert(slug, '摘要不存在');
     assert(thumbnail, '缩略图不存在');
     assert(content, '内容不存在');
     const { Content: model } = this.ctx.model;
     const createAt = moment().format('x');
+    let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+    text = text.replace('\\s*|\t|\r|\n', '');
+    const slug = text.substring(0, 200);
     try {
-      await model.create({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, createAt, year, datte, annexname });
+      const year = date.slice(0, 3) + '年';
+      await model.create({ title, slug, thumbnail, annex, content, istop, columns, createAt, year, date, annexname, term, hits: 0 });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '添加失败' });
     }
   }
-  async update({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, _id, year, datte, annexname }) {
+  async update({ title, thumbnail, annex, content, istop, columns, _id, year, datte, annexname }) {
     assert(_id, 'id不存在');
     const { Content: model } = this.ctx.model;
+    let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+    text = text.replace('\\s*|\t|\r|\n', '');
+    const slug = text.substring(0, 200);
     try {
-      await model.findById(_id).update({ title, shortTitle, slug, thumbnail, annex, content, istop, columnList, year, datte, annexname });
+      await model.findById(_id).update({ title, slug, thumbnail, annex, content, istop, columns, year, datte, annexname });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '修改失败' });
@@ -44,19 +49,24 @@ class ContentService extends Service {
     const { Content: model } = this.ctx.model;
     try {
       const res = await model.findById(id);
+      const token = Boolean(this.ctx.request.header.authorization);
+      if (!token) {
+        const hits = res.hits++;
+        await model.findById(id).update({ hits });
+      }
       return { errmsg: '', errcode: 0, data: res };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '删除失败' });
     }
   }
-  async query({ skip, limit, title, code }) {
+  async query({ skip, limit, title, columns }) {
     const { Content: model } = this.ctx.model;
     const filter = {};
     if (title) filter.title = title;
     const total = await model.find();
     try {
-      if (code) {
-        const list = await model.find({ columnList: { $in: [ code ] } }).skip(Number(skip) * Number(limit)).limit(Number(limit));
+      if (columns) {
+        const list = await model.find({ columns }).skip(Number(skip) * Number(limit)).limit(Number(limit));
         return { errmsg: '', errcode: 0, data: list, total: total.length };
       }
       let res;
@@ -70,6 +80,21 @@ class ContentService extends Service {
       throw new Error({ errcode: -2001, errmsg: '查询失败' });
     }
   }
+  async filepath() {
+    const { Content: model } = this.ctx.model;
+    try {
+      const res = await model.find();
+      for (let i = 0; i < res.length; i++) {
+        const content = res[i].content;
+        let txet = content.replace(new RegExp(/\/files\/images\/\d{6}\//, 'gm'), '/filespath/resource/');
+        txet = txet.replace(new RegExp(/JPG/, 'gm'), 'jpg');
+        await model.findById(res[i]._id).update({ ...res, content: txet });
+      }
+      return { errmsg: '', errcode: 0, res };
+    } catch (error) {
+      throw new Error({ errcode: -2001, errmsg: '删除失败' });
+    }
+  }
 }
 
 module.exports = ContentService;

+ 3 - 0
app/service/files.js

@@ -76,6 +76,9 @@ class FilesService extends Service {
       const uuid = uuidv1();
       const filepath = `/filespath/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
       const paths = path.join(`${this.app.config.filespath}${filepath}`);
+
+      // const filepath = `/public/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
+      // const paths = path.join(this.app.baseDir, `/app${filepath}`);
       // 存储
       const result = await new Promise((resolve, reject) => {
         const remoteFileStream = fs.createWriteStream(paths);

+ 14 - 6
app/service/page.js

@@ -4,26 +4,34 @@ const Service = require('egg').Service;
 const assert = require('assert');
 const moment = require('moment');
 class PageService extends Service {
-  async create({ title, shortTitle, slug, annex, content, istop, menu, annexname }) {
+  async create({ title, annex, content, istop, menu, annexname, date }) {
     assert(title, '标题不存在');
-    assert(shortTitle, '短标题不存在');
-    assert(slug, '摘要不存在');
     assert(content, '内容不存在');
     assert(content, '内容不存在');
     const { Page: model } = this.ctx.model;
     const createAt = moment().format('x');
     try {
-      await model.create({ title, shortTitle, slug, annex, content, istop, menu, createAt, annexname });
+      let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+      text = text.replace('\\s*|\t|\r|\n', '');
+      const slug = text.substring(0, 200);
+      const menus = await model.find(menu);
+      if (menus.length > 0) return { errmsg: '不能重复绑定菜单', errcode: -2001 };
+      await model.create({ title, slug, date, annex, content, istop, menu, createAt, annexname });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '添加失败' });
     }
   }
-  async update({ title, shortTitle, slug, annex, content, istop, menu, _id, annexname }) {
+  async update({ title, annex, content, istop, menu, _id, annexname, date }) {
     assert(_id, 'id不存在');
     const { Page: model } = this.ctx.model;
     try {
-      await model.findById(_id).update({ title, shortTitle, slug, annex, content, istop, menu, annexname });
+      let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
+      text = text.replace('\\s*|\t|\r|\n', '');
+      const slug = text.substring(0, 200);
+      const menus = await model.find(menu);
+      if (menus.length > 0 && menus[0]._id !== _id) return { errmsg: '不能重复绑定菜单', errcode: -2001 };
+      await model.findById(_id).update({ title, date, slug, annex, content, istop, menu, annexname });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error({ errcode: -2001, errmsg: '修改失败' });

+ 5 - 4
config/config.default.js

@@ -32,11 +32,12 @@ module.exports = appInfo => {
   const userConfig = {
     // myAppName: 'egg',
   };
+  // 解除上传大小限制
+  config.bodyParser = {
+    jsonLimit: '100mb',
+    formLimit: '100mb',
+  };
   // 解除文件上传大小限制
-  // config.bodyParser = {
-  //   jsonLimit: '100mb',
-  //   formLimit: '100mb',
-  // };
   config.multipart = {
     fileSize: '50mb',
     mode: 'stream',