174 lines
7.2 KiB
TypeScript
174 lines
7.2 KiB
TypeScript
import { Request, Response,NextFunction } from 'express';
|
||
import axios from 'axios';
|
||
import { selectApi,getFiliUrl,createUserApi } from '../util/curd';
|
||
import { wazpApiUrl,sousuoUrl,createuserUrl } from '../util/Resource';
|
||
|
||
class IndexController {
|
||
zuopinGet = async (req: Request, res: Response, next: NextFunction) => {
|
||
const danganleixing = req.query.danganleixing;
|
||
const pageNumber = req.query.pageNumber;
|
||
const pageSize = req.query.pageSize;
|
||
//在TypeScript中,当你在对象字面量属性名和变量名相同时,可以省略冒号后面的变量名。所以danganleixing:danganleixing可以简写为danganleixing。
|
||
const temp = selectApi({ danganleixing }, pageNumber, pageSize, wazpApiUrl);
|
||
|
||
temp.then(async (response) => {
|
||
const promises = [];
|
||
for (const key in response.data.content) {
|
||
promises.push(getFiliUrl(response.data.content[key]['xiaoguotu']).then((url) => {
|
||
response.data.content[key]['xiaoguotu'] = url;
|
||
}));
|
||
promises.push(getFiliUrl(response.data.content[key]['wenyangtupian']).then((url) => {
|
||
response.data.content[key]['wenyangtupian'] = url;
|
||
}));
|
||
}
|
||
|
||
await Promise.all(promises);
|
||
res.send(response.data);
|
||
})
|
||
.catch(next); // 如果有错误,传递给后续的错误处理中间件
|
||
};
|
||
|
||
|
||
|
||
// 纹样查询
|
||
wenyangGet = async (req: Request, res: Response, next: NextFunction) => {
|
||
const danganleixing = req.query.danganleixing;
|
||
const pageNumber = req.query.pageNumber;
|
||
const pageSize = req.query.pageSize;
|
||
|
||
const temp = selectApi({ danganleixing }, pageNumber, pageSize, wazpApiUrl);
|
||
|
||
temp.then(async (response) => {
|
||
const promises = [];
|
||
for (const key in response.data.content) {
|
||
promises.push(getFiliUrl(response.data.content[key]['yuanshitupian']).then((url) => {
|
||
response.data.content[key]['yuanshitupian'] = url;
|
||
}));
|
||
}
|
||
|
||
await Promise.all(promises);
|
||
res.send(response.data);
|
||
})
|
||
.catch(next); // 如果有错误,传递给后续的错误处理中间件
|
||
};
|
||
|
||
// 搜索查询
|
||
sousuoGet = async (req: Request, res: Response, next: NextFunction) => {
|
||
const danganleixing = req.query.danganleixing;
|
||
const pageNumber = req.query.pageNumber;
|
||
const pageSize = req.query.pageSize;
|
||
console.log(danganleixing)
|
||
const temp = selectApi({ and_like_mingcheng:danganleixing }, pageNumber, pageSize, sousuoUrl);
|
||
|
||
temp.then(async (response) => {
|
||
const promises = [];
|
||
for (const key in response.data.content) {
|
||
promises.push(getFiliUrl(response.data.content[key]['yuanshitupian']).then((url) => {
|
||
response.data.content[key]['yuanshitupian'] = url;
|
||
|
||
} ) );
|
||
promises.push(getFiliUrl(response.data.content[key]['xiaoguotu']).then((url) => {
|
||
response.data.content[key]['xiaoguotu'] = url;
|
||
|
||
} ) );
|
||
promises.push(getFiliUrl(response.data.content[key]['wenyangtupian']).then((url) => {
|
||
response.data.content[key]['wenyangtupian'] = url;
|
||
|
||
} ) );
|
||
}
|
||
|
||
await Promise.all(promises);
|
||
res.send(response.data);
|
||
})
|
||
.catch(next); // 如果有错误,传递给后续的错误处理中间件
|
||
};
|
||
|
||
//筛选查询
|
||
shaixuanGet = async (req: Request, res: Response, next: NextFunction) => {
|
||
const leixing = req.query.leixing;
|
||
const foundKey = req.query.foundKey;
|
||
const pageNumber = req.query.pageNumber;
|
||
const pageSize = req.query.pageSize;
|
||
if(leixing=="minzu"){
|
||
const temp = selectApi({"minzu":foundKey}, pageNumber, pageSize, sousuoUrl);
|
||
temp.then(async(response)=>{
|
||
const promises = [];
|
||
for (const key in response.data.content) {
|
||
|
||
if(response.data.content[key]['yuanshitupian']!=''){
|
||
|
||
promises.push(getFiliUrl(response.data.content[key]['yuanshitupian']).then((url) => {
|
||
response.data.content[key]['yuanshitupian'] = url;
|
||
}))
|
||
}else if(response.data.content[key]['xiaoguotu']!=''){
|
||
promises.push(getFiliUrl(response.data.content[key]['xiaoguotu']).then((url) => {
|
||
response.data.content[key]['xiaoguotu'] = url;
|
||
}))
|
||
}else if(response.data.content[key]['wenyangtupian']!=''){
|
||
promises.push(getFiliUrl(response.data.content[key]['wenyangtupian']).then((url) => {
|
||
response.data.content[key]['wenyangtupian'] = url;
|
||
|
||
}))
|
||
}else{
|
||
|
||
}
|
||
}
|
||
await Promise.all(promises);
|
||
res.send(response.data);
|
||
})
|
||
|
||
}else{
|
||
const temp = selectApi({"jifa":foundKey}, pageNumber, pageSize, sousuoUrl);
|
||
temp.then(async(response)=>{
|
||
const promises = [];
|
||
for (const key in response.data.content) {
|
||
|
||
if(response.data.content[key]['yuanshitupian']!=''){
|
||
|
||
promises.push(getFiliUrl(response.data.content[key]['yuanshitupian']).then((url) => {
|
||
response.data.content[key]['yuanshitupian'] = url;
|
||
}))
|
||
}else if(response.data.content[key]['xiaoguotu']!=''){
|
||
promises.push(getFiliUrl(response.data.content[key]['xiaoguotu']).then((url) => {
|
||
response.data.content[key]['xiaoguotu'] = url;
|
||
}))
|
||
}else if(response.data.content[key]['wenyangtupian']!=''){
|
||
promises.push(getFiliUrl(response.data.content[key]['wenyangtupian']).then((url) => {
|
||
response.data.content[key]['wenyangtupian'] = url;
|
||
|
||
}))
|
||
}else{
|
||
|
||
}
|
||
}
|
||
await Promise.all(promises);
|
||
res.send(response.data);
|
||
})
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
// 注册
|
||
register = async (req: Request, res: Response,next: NextFunction) => {
|
||
// ...内部的具体注册逻辑
|
||
const name = req.query.name;
|
||
const password = req.query.password;
|
||
const Mobile = req.query.Mobile;
|
||
const userType = req.query.userType;
|
||
const temp = createUserApi(name,password,Mobile,userType,createuserUrl);
|
||
temp.then((response) => {
|
||
if(response.message=="SUCCESS"){
|
||
res.send(response.message);
|
||
}
|
||
|
||
});
|
||
};
|
||
}
|
||
|
||
|
||
|
||
// 创建一个上述类的一个实例,将其导出
|
||
export const indexController = new IndexController();
|
||
export default indexController; |