mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	分页查询添加
This commit is contained in:
		
							parent
							
								
									7cf0756eb6
								
							
						
					
					
						commit
						081ac958c9
					
				
							
								
								
									
										2
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							@ -1,5 +1,5 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "check-ts",
 | 
					  "name": "backend-ts",
 | 
				
			||||||
  "version": "1.0.0",
 | 
					  "version": "1.0.0",
 | 
				
			||||||
  "lockfileVersion": 1,
 | 
					  "lockfileVersion": 1,
 | 
				
			||||||
  "requires": true,
 | 
					  "requires": true,
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "check-ts",
 | 
					  "name": "backend-ts",
 | 
				
			||||||
  "version": "1.0.0",
 | 
					  "version": "1.0.0",
 | 
				
			||||||
  "description": "",
 | 
					  "description": "API接口",
 | 
				
			||||||
  "main": "index.js",
 | 
					  "main": "index.js",
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "build": "tsc",
 | 
					    "build": "tsc",
 | 
				
			||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
    "start": "nodemon ./dist/server.js",
 | 
					    "start": "nodemon ./dist/server.js",
 | 
				
			||||||
    "prod": "npm run build && npm run start"
 | 
					    "prod": "npm run build && npm run start"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "author": "Coral Ram",
 | 
					  "author": "team",
 | 
				
			||||||
  "license": "ISC",
 | 
					  "license": "ISC",
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "nodemon": "^1.19.4",
 | 
					    "nodemon": "^1.19.4",
 | 
				
			||||||
 | 
				
			|||||||
@ -16,9 +16,9 @@ export default {
 | 
				
			|||||||
  options: {
 | 
					  options: {
 | 
				
			||||||
    swaggerDefinition: {
 | 
					    swaggerDefinition: {
 | 
				
			||||||
      info: {
 | 
					      info: {
 | 
				
			||||||
        description: 'This is a server',
 | 
					        description: 'CURD-TS专用接口',
 | 
				
			||||||
        title: 'Swagger',
 | 
					        title: 'Swagger',
 | 
				
			||||||
        version: '1.0.0'
 | 
					        version: require('../../package.json').version
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      host: `localhost:${parseInt(process.env.PORT, 10)}`,
 | 
					      host: `localhost:${parseInt(process.env.PORT, 10)}`,
 | 
				
			||||||
      basePath: '/',
 | 
					      basePath: '/',
 | 
				
			||||||
@ -29,7 +29,7 @@ export default {
 | 
				
			|||||||
          type: 'apiKey',
 | 
					          type: 'apiKey',
 | 
				
			||||||
          in: 'header',
 | 
					          in: 'header',
 | 
				
			||||||
          name: 'Authorization',
 | 
					          name: 'Authorization',
 | 
				
			||||||
          description: ''
 | 
					          description: 'Bearer Authorization'
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -12,14 +12,7 @@ export interface dataModel {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 保存验证码
 | 
					// 保存验证码
 | 
				
			||||||
let generateVerify: number | string
 | 
					let generateVerify: number
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @typedef Login
 | 
					 | 
				
			||||||
 * @property {string} username.required - 用户名
 | 
					 | 
				
			||||||
 * @property {string} password.required - 密码
 | 
					 | 
				
			||||||
 * @property {string} verify.required - 验证码
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @typedef Error
 | 
					 * @typedef Error
 | 
				
			||||||
@ -31,12 +24,21 @@ let generateVerify: number | string
 | 
				
			|||||||
 * @property {[integer]} code
 | 
					 * @property {[integer]} code
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @typedef Login
 | 
				
			||||||
 | 
					 * @property {string} username.required - 用户名 - eg: admin
 | 
				
			||||||
 | 
					 * @property {string} password.required - 密码 - eg: 123456
 | 
				
			||||||
 | 
					 * @property {integer} verify.required - 验证码
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 登录
 | 
					 * 登录
 | 
				
			||||||
 * @route POST /login
 | 
					 * @route POST /login
 | 
				
			||||||
 * @param {Login.model} point.body.required - the new point
 | 
					 * @param {Login.model} point.body.required - the new point
 | 
				
			||||||
 * @produces application/json application/xml
 | 
					 * @produces application/json application/xml
 | 
				
			||||||
 * @consumes application/json application/xml
 | 
					 * @consumes application/json application/xml
 | 
				
			||||||
 | 
					 * @summary 登录
 | 
				
			||||||
 | 
					 * @group 用户登录、注册相关
 | 
				
			||||||
 * @returns {Response.model} 200 
 | 
					 * @returns {Response.model} 200 
 | 
				
			||||||
 * @returns {Array.<Login>} Login
 | 
					 * @returns {Array.<Login>} Login
 | 
				
			||||||
 * @headers {integer} 200.X-Rate-Limit 
 | 
					 * @headers {integer} 200.X-Rate-Limit 
 | 
				
			||||||
@ -79,9 +81,9 @@ const login = async (req: Request, res: Response) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @typedef Register
 | 
					 * @typedef Register
 | 
				
			||||||
 * @property {string} username.required - 用户名
 | 
					 * @property {string} username.required - 用户名 - eg: admin
 | 
				
			||||||
 * @property {string} password.required - 密码
 | 
					 * @property {string} password.required - 密码 - eg: 123456
 | 
				
			||||||
 * @property {string} verify.required - 验证码
 | 
					 * @property {integer} verify.required - 验证码
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -90,6 +92,8 @@ const login = async (req: Request, res: Response) => {
 | 
				
			|||||||
* @param {Register.model} point.body.required - the new point
 | 
					* @param {Register.model} point.body.required - the new point
 | 
				
			||||||
* @produces application/json application/xml
 | 
					* @produces application/json application/xml
 | 
				
			||||||
* @consumes application/json application/xml
 | 
					* @consumes application/json application/xml
 | 
				
			||||||
 | 
					* @summary 注册
 | 
				
			||||||
 | 
					* @group 用户登录、注册相关
 | 
				
			||||||
* @returns {Response.model} 200
 | 
					* @returns {Response.model} 200
 | 
				
			||||||
* @returns {Array.<Register>} Register
 | 
					* @returns {Array.<Register>} Register
 | 
				
			||||||
* @headers {integer} 200.X-Rate-Limit
 | 
					* @headers {integer} 200.X-Rate-Limit
 | 
				
			||||||
@ -136,7 +140,7 @@ const register = async (req: Request, res: Response) => {
 | 
				
			|||||||
 * 列表更新
 | 
					 * 列表更新
 | 
				
			||||||
 * @route GET /updateList
 | 
					 * @route GET /updateList
 | 
				
			||||||
 * @summary 列表更新
 | 
					 * @summary 列表更新
 | 
				
			||||||
 * @group updateList - 列表更新
 | 
					 * @group 用户管理相关
 | 
				
			||||||
 * @returns {object} 200 
 | 
					 * @returns {object} 200 
 | 
				
			||||||
 * @security JWT
 | 
					 * @security JWT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -149,7 +153,7 @@ const updateList = async (req: Request, res: Response) => {
 | 
				
			|||||||
 * 列表删除
 | 
					 * 列表删除
 | 
				
			||||||
 * @route GET /deleteList
 | 
					 * @route GET /deleteList
 | 
				
			||||||
 * @summary 列表删除
 | 
					 * @summary 列表删除
 | 
				
			||||||
 * @group deleteList - 列表删除
 | 
					 * @group 用户管理相关
 | 
				
			||||||
 * @returns {object} 200 
 | 
					 * @returns {object} 200 
 | 
				
			||||||
 * @security JWT
 | 
					 * @security JWT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -158,23 +162,53 @@ const deleteList = async (req: Request, res: Response) => {
 | 
				
			|||||||
  res.json({ code: 1, msg: "成功" })
 | 
					  res.json({ code: 1, msg: "成功" })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @typedef SearchPage
 | 
				
			||||||
 | 
					 * @property {integer} page.required - 第几页 - eg: 1
 | 
				
			||||||
 | 
					 * @property {integer} size.required - 数据量(条)- eg: 5
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* 分页查询
 | 
					* 分页查询
 | 
				
			||||||
* @route GET /searchPage
 | 
					* @route POST /searchPage
 | 
				
			||||||
 | 
					* @param {SearchPage.model} point.body.required - the new point
 | 
				
			||||||
 | 
					* @produces application/json application/xml
 | 
				
			||||||
 | 
					* @consumes application/json application/xml
 | 
				
			||||||
* @summary 分页查询
 | 
					* @summary 分页查询
 | 
				
			||||||
* @group searchPage - 分页查询
 | 
					* @group 用户管理相关
 | 
				
			||||||
* @returns {object} 200 
 | 
					* @returns {Response.model} 200
 | 
				
			||||||
 | 
					* @returns {Array.<SearchPage>} SearchPage
 | 
				
			||||||
 | 
					* @headers {integer} 200.X-Rate-Limit
 | 
				
			||||||
 | 
					* @headers {string} 200.X-Expires-After
 | 
				
			||||||
* @security JWT
 | 
					* @security JWT
 | 
				
			||||||
* @returns {Error}  default - Unexpected error
 | 
					 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const searchPage = async (req: Request, res: Response) => {
 | 
					const searchPage = async (req: Request, res: Response) => {
 | 
				
			||||||
  res.json({ code: 1, msg: "成功" })
 | 
					  const { page, size } = req.body
 | 
				
			||||||
 | 
					  let payload = null
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const authorizationHeader = req.get("Authorization")
 | 
				
			||||||
 | 
					    const accessToken = authorizationHeader.substr("Bearer ".length)
 | 
				
			||||||
 | 
					    payload = jwt.verify(accessToken, secret.jwtSecret)
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    return res.status(401).end()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let sql = 'select * from users limit ' + size + ' offset ' + size * (page - 1)
 | 
				
			||||||
 | 
					  connection.query(sql, async function (err, data) {
 | 
				
			||||||
 | 
					    if (err) {
 | 
				
			||||||
 | 
					      Logger.error(err)
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      await res.json({
 | 
				
			||||||
 | 
					        code: 0,
 | 
				
			||||||
 | 
					        info: data
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @typedef SearchVague
 | 
					 * @typedef SearchVague
 | 
				
			||||||
 * @property {string} username.required - 用户名
 | 
					 * @property {string} username.required - 用户名  - eg: admin
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -183,6 +217,8 @@ const searchPage = async (req: Request, res: Response) => {
 | 
				
			|||||||
* @param {SearchVague.model} point.body.required - the new point
 | 
					* @param {SearchVague.model} point.body.required - the new point
 | 
				
			||||||
* @produces application/json application/xml
 | 
					* @produces application/json application/xml
 | 
				
			||||||
* @consumes application/json application/xml
 | 
					* @consumes application/json application/xml
 | 
				
			||||||
 | 
					* @summary 模糊查询
 | 
				
			||||||
 | 
					* @group 用户管理相关
 | 
				
			||||||
* @returns {Response.model} 200
 | 
					* @returns {Response.model} 200
 | 
				
			||||||
* @returns {Array.<SearchVague>} SearchVague
 | 
					* @returns {Array.<SearchVague>} SearchVague
 | 
				
			||||||
* @headers {integer} 200.X-Rate-Limit
 | 
					* @headers {integer} 200.X-Rate-Limit
 | 
				
			||||||
@ -235,7 +271,7 @@ const captcha = async (req: Request, res: Response) => {
 | 
				
			|||||||
    mathMax: 4,
 | 
					    mathMax: 4,
 | 
				
			||||||
    mathOperator: "+"
 | 
					    mathOperator: "+"
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
  generateVerify = create.text
 | 
					  generateVerify = Number(create.text)
 | 
				
			||||||
  res.type('svg') // 响应的类型
 | 
					  res.type('svg') // 响应的类型
 | 
				
			||||||
  res.json({ code: 1, msg: create.text, svg: create.data })
 | 
					  res.json({ code: 1, msg: create.text, svg: create.data })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -35,8 +35,8 @@ app.get('/deleteList', (req, res) => {
 | 
				
			|||||||
  deleteList(req, res)
 | 
					  deleteList(req, res)
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('/register', (req, res) => {
 | 
					app.post('/searchPage', (req, res) => {
 | 
				
			||||||
  register(req, res)
 | 
					  searchPage(req, res)
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.post('/searchVague', (req, res) => {
 | 
					app.post('/searchVague', (req, res) => {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user