Commit 981f14b1 by maguoliang

s

parent 3a86157a
import { getUserPermission, getManagePermission } from "../data/interface/pagePermissions";
import { BizError } from "../util/bizError";
export async function getUserPer(req, res) {
let {sessionid, userId} = req.body
console.log(userId, "userId")
// sessionid等接入统一认证后,再校验
if(!userId) throw new BizError("请求参数错误");
let ret = await getUserPermission(sessionid, userId);
res.send(ret);
}
export async function managePermission(req, res) {
let {sessionid, userId} = req.body
console.log(userId, "userId")
// sessionid等接入统一认证后,再校验
if(!userId) throw new BizError("请求参数错误");
let ret = await getManagePermission(sessionid, userId);
res.send(ret);
}
const fs = require("fs");
const path = require("path");
// 读取json文件数据
export async function readFile (fileUrl) {
let url = path.join(__dirname.substring(0,__dirname.indexOf("out")), fileUrl);
let data = fs.readFileSync(url);
let person = data.toString();//二进制转化为字符串
person = JSON.parse(person);//将字符串转换为json对象
return person
}
/**
* 对json文件进行添加的操作
* @param fileUrl 文件路径
......
......@@ -198,16 +198,17 @@ export async function getActivityListData() {
return dataList || [];
}
//数字换管理平台数据
//数字管理平台列表
export async function getManagePlatformData(currentpage, allow, search) {
// await get获取token();
let {data} = await readFile(userUrl)
let {data} = await cord.readFile(userUrl)
//全量的数据
let array = []
// 第一层遍历拿到arr[i].allow所有用户能看到的页面数组。
for (let i=0; i<data.length; i++) {
data[i].number = i+1
// 第二层遍历拿到所有用户能看到的页面名称。
for(let j=0; j<data[i].allow.length; j++) {
......@@ -230,6 +231,7 @@ export async function getManagePlatformData(currentpage, allow, search) {
let searchArr = []
if (search!=="") {
for (let i=0; i<newArr.length; i++) {
// 如果某条名称和姓名包含同一个字符,这条数据会重复push到searchArr。 在第242行数组去重。
if(newArr[i].name.indexOf(search) !== -1) searchArr.push(newArr[i])
if(newArr[i].phoneNumber.indexOf(search) !== -1) searchArr.push(newArr[i])
}
......@@ -237,11 +239,14 @@ export async function getManagePlatformData(currentpage, allow, search) {
searchArr = newArr
}
// 经过页面权限、姓名、手机号筛选、去重过后最终返回的数据
const resArr = [...new Set(searchArr)]
// 每页10条数据,totalPage一共多少页
const totalPage = Math.ceil(searchArr.length/10)
const totalPage = Math.ceil(resArr.length/10)
// 每页十条数据,用slice处理原数据做分页
const dataList = [...new Set(searchArr)].slice((currentpage-1)*10, currentpage*10)
const dataList = resArr.slice((currentpage-1)*10, currentpage*10)
let ret:any = {
userName: "王小虎",
......@@ -250,33 +255,24 @@ export async function getManagePlatformData(currentpage, allow, search) {
pagenation: {
currentPage: currentpage,
totalPage,
totalNum: searchArr.length,
totalNum: resArr.length,
}
}
return ret;
}
//数字换管理平台数据
//更新数字管理平台数据,用户权限
export async function updateManagePlatform(params) {
// await get获取token();
//更新json里面的数据
await cord.updataJson(userUrl, params.id, params)
await readFile(userUrl)
await cord.readFile(userUrl)
return {
code:200,
msg: "修改成功",
success: true
};
}
// 读取json文件数据
function readFile (fileUrl) {
let url = path.join(__dirname.substring(0,__dirname.indexOf("out")), fileUrl);
let data = fs.readFileSync(url);
let person = data.toString();//二进制转化为字符串
person = JSON.parse(person);//将字符串转换为json对象
return person
}
\ No newline at end of file
// 二级页面 it服务管理模块 用户权限(当前登录用户可以看到那些大屏页面)
import * as cord from "../crod"
const userUrl = './mock/platform.json';
export async function getUserPermission (sessionid: string, userId: string) {
// 暂不校验sessionid。 接入统一认证后,需要校验sessionid是否有效。
let ret:any = {
code: 200,
success: true,
}
let {data} = await cord.readFile(userUrl)
let idArr = []
for (let i = 0; i<data.length; i++) {
idArr.push(data[i].id)
}
if (idArr.indexOf(userId) === -1) {
ret.msg = "userId不存在!"
} else {
for (let i = 0; i<data.length; i++) {
if(userId === data[i].id) {
ret.allow = data[i].allow
}
}
}
return ret;
}
export async function getManagePermission(sessionid: string, userId: string) {
// 暂不校验sessionid。 接入统一认证后,需要校验sessionid是否有效。
let ret:any = {
code: 200,
success: true,
}
let {data} = await cord.readFile(userUrl)
let idArr = []
for (let i = 0; i<data.length; i++) {
idArr.push(data[i].id)
}
if (idArr.indexOf(userId) === -1) {
ret.hasPermission = false
ret.code = 500
ret.success = false
} else {
for (let i = 0; i<data.length; i++) {
if(userId === data[i].id) {
ret.hasPermission = data[i].hasPermission
}
}
}
return ret;
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import * as sjzltxBiz from '../biz/sjzltx';
import * as ztyxtsBiz from '../biz/ztyxts';
import * as zyhdbzBiz from '../biz/zyhdbz';
import * as glptlb from '../biz/glptlb';
import * as pagePermission from '../biz/pagePermissions';
export function setRouter(httpServer){
httpServer.get('/sjzltx', asyncHandler(sjzltxBiz.getData));
......@@ -17,9 +18,14 @@ export function setRouter(httpServer){
httpServer.get('/zyhdbzpop', asyncHandler(zyhdbzBiz.getPopData));
httpServer.post('/zyhdbzpop', asyncHandler(zyhdbzBiz.getPopData));
httpServer.get('/glptlb', asyncHandler(glptlb.getData));
// httpServer.get('/glptlb', asyncHandler(glptlb.getData));
httpServer.post('/glptlb', asyncHandler(glptlb.getData));
httpServer.get('/glptlb/update', asyncHandler(glptlb.update));
// httpServer.get('/glptlb/update', asyncHandler(glptlb.update));
httpServer.post('/glptlb/update', asyncHandler(glptlb.update));
httpServer.post('/getUserPermission', asyncHandler(pagePermission.getUserPer));
// httpServer.get('/getUserPermission', asyncHandler(pagePermission.getUserPer));
httpServer.post('/managePermission', asyncHandler(pagePermission.managePermission));
}
\ No newline at end of file
//端口
export function getPort() : number {
return Number(process.env.PORT) || Number(process.argv[3]) || 999;//测试环境7474
return Number(process.env.PORT) || Number(process.argv[3]) || 7474;//测试环境7474
}
// sit 测试环境 prod 生产环境 dem 演示环境(测试数据,前端无密码访问)
......@@ -14,12 +14,3 @@ export let requestConfig = {
client_id:'75cb2a016ec640a886f681b2d3ae6f3c',
client_secret:'df795bea090e441fba6361645d18d5de'
};
function getDBUrl(){
return 'mongodb://127.0.0.1:27017/keyi_platform';
}
//mongo数据库连接字符
export const mongoServerConstVal = {
platformDBUrl:getDBUrl()
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment