management_system
Introduction
This is a background management system based on koa2
Use jQuery
as the front-end JS framework Use bootstrap
as the CSS framework Use pug
/ jade
and handlebars
as the HTML page template Use PostgreSql
to store business data Use mongodb
to store session
Using Bookshelf
+ Knex
as ORM
and Query Builder
Use Sentry
as a platform for collecting feedback on error information. Use AJAX
to process front-end requests. Use the CronJob
library to complete the execution of scheduled tasks.
For the directory structure and babel configuration, please refer to https://github.com/17koa/koa-demo
The original link seems to have been deleted. This is the version I forked https://github.com/liuyueyi1995/koa2-demo
The front-end code of the website comes from one of my previous projects https://github.com/liuyueyi1995/oa
basic tasks
- A Backend administrator login registration
- B User information management
- C user role management
- D Organizational Management
- E project management
- F Display the content obtained by query and search through back-end paging +
AJAX
- G Creation of temporary users and allocation and recycling of temporary roles
- H log management
Completeness
- The basic MVC structure has been completed;
- Task A has been completed, including registration, login, and session reading and writing;
- Task B has been completed, including user information query, fuzzy search, addition, deletion, modification of basic information, and password modification;
- Task C has been completed, including multi-table query, fuzzy search, cascading drop-down menu processing, information addition and deletion;
- Task D has been completed, including institutional information query, fuzzy search, addition, deletion, and modification;
- Task E has been completed, including project information query, fuzzy search, addition, deletion, and modification;
- Task F has been completed. By judging whether the search box has content when the paging button click event is triggered, the result set returned by the background is determined;
- Task G has been completed. By dividing users into internal and external users, using different password generation methods, adding expiration time attributes to roles, the background regularly cleans up expired role information;
- Task G has been completed, including log viewing and fuzzy search;
- The presentation form of the form has been improved, the drop-down menu has been modified, a date control has been added, and Boolean value input is in the form of radio;
- The two functions of user login and data management have been associated;
- The distinction between external and internal roles has been completed, and the deadline setting of the roles has been completed;
TODOs
- Query for dates, numbers, and Boolean values needs to be improved (for example: timestamp, boolean);
- The verification of user input needs to be improved (for example: email, phone);
- Improve the degree of code reuse;
Focus
The config.js
file containing sensitive information has been deleted from the repo and needs to be added when using it:
var config = {
database: '',
username: '',
password: '',
host: '',
port:
};
module.exports = config;
ISSUEs
- There is a bug in the cascading menu. Initially, the
site
list cannot be displayed without changing type
.- Resolved.
- It should be a problem with
onchange
. - By adding a default null value to the
type
drop-down menu, force the user to change it.
- After modifying the database, the
updated_at
value has not changed.- Resolved.
- Just add
hasTimestamps:true
when defining model
.
- After modifying the database, the order of the list will be disrupted.
- Resolved.
- Use
orderBy
to sort the search results before the database returns them.
- On the role management page, when the site value is empty, the addition may occasionally fail.
- Resolved.
- When the front-end
null
is returned to the back-end, it becomes an empty string, which conflicts with integer
type of the foreign key.
- After paging, if the subsequent content is modified, it will jump back to the first page after the modification is successful.
- Not resolved .
- It should be a
reload
problem.
- After paging, if the search results have multiple pages of content, clicking on the second page will return to the second page of the original results.
- Resolved.
- Because there is only one paging
AJAX
processing now, if you want the search results to be displayed in paging, you need to add another state. - Add judgment based on the original paging,
- If there is content in the search box at this time, the database will be queried with this content and the content of the corresponding page will be returned;
- If the search box is empty at this time, the content of the page corresponding to the original data will be returned.
- After searching, the number of pages in the paging component is incorrect. For example, the original results have 5 pages, but the search results only have 2 pages, but 5 page number buttons are still displayed.
- Resolved.
- After searching, get the number of results and redraw the paging button.
- When searching multiple times, the number of pages in the paging component is incorrect. For example, the first search result has 2 pages, and the second search result has 3 pages, but still only 2 page number buttons are displayed.
- Resolved.
- Get the content of the search box in real time, and refresh the page when its content becomes empty.
- When using the
handlebars
template, the timestamp is parsed incorrectly.- Resolved.
- Use a custom
helper
to parse timestamps.
- If you are not logged in, modifying the URL will skip the login and operate the database directly.
- Resolved.
- Before returning each
get
request, add session
judgment. If session
is empty, jump to login
page.
- Deletion of internal users requires join. pgsql's delete only supports
using
, and bookshelf does not support using
.- Resolved.
- Use
knex
to complete the query directly instead.
- date/time field value out of range
- Resolved.
- Although the local test database and the Alibaba Cloud database are both pgsql9.4, the review mechanisms are different.
- Alibaba Cloud's date discrimination seems to be unable to appear in morning and afternoon (AM/PM)
- Therefore, a
format
method was added to the Date
class for formatting dates.
- Switching between search results and all results.
- Resolved.
- The earliest method was to use real-time monitoring. When the search box is empty, the page is refreshed, but this is invalid on some browsers and operating systems;
- Therefore, instead use the method of linking in the banner to give a link from the search results to all results.
- The long date format takes up too many pages.
- Resolved.
- On the backend, handle the date by formatting it, simplifying it.
- If an error is reported in the background database operation, the front end will not get feedback of relevant information.
- Resolved.
- Add a then().catch() block to the backend to make error judgments.
- The next step is to analyze the specific error code and inform the front end of the detailed information.
- When adding roles, users with the same name cannot be distinguished.
- Resolved.
- Distinguish users with the same name by indicating their email address after the username.