Commit 4b3ecb9b authored by mengwenhao's avatar mengwenhao

Merge branch 'test' of https://git.yidian-inc.com:8021/bp/op-web-service into test

parents 9b2fe1b0 f4835bcb
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/5p/f45l166j057533bqfd5n9w880000gp/T/jest_dy",
// Automatically clear mock calls and instances between every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,
// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// The directory where Jest should output its coverage files
// coverageDirectory: undefined,
// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// A path to a custom dependency extractor
// dependencyExtractor: undefined,
// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,
// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
moduleFileExtensions: ["js", "json", "vue"],
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
"@/(.*)$": "<rootDir>/src/$1"
},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
// preset: undefined,
// Run tests from one or more projects
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state between every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: undefined,
// Automatically restore mock state between every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
testEnvironment: "jsdom",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",
// A map from regular expressions to paths to transformers
transform: {
"^.+\\.vue$": "vue3-jest",
"^.+\\.js$": "babel-jest"
}
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
// verbose: undefined,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"web-dev": "NODE_ENV=development vue-cli-service serve", "web-dev": "NODE_ENV=development vue-cli-service serve",
"web-test": "NODE_ENV=test vue-cli-service build", "web-test": "NODE_ENV=test vue-cli-service build",
"web-build": "NODE_ENV=production vue-cli-service build", "web-build": "NODE_ENV=production vue-cli-service build",
"test:unit": "vue-cli-service test:unit", "test:unit": "jest",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
"vuex": "^4.0.0-beta.4" "vuex": "^4.0.0-beta.4"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/vue": "^6.4.2",
"@vue/cli-plugin-babel": "^4.5.6", "@vue/cli-plugin-babel": "^4.5.6",
"@vue/cli-plugin-eslint": "^4.5.6", "@vue/cli-plugin-eslint": "^4.5.6",
"@vue/cli-plugin-unit-jest": "^4.5.6", "@vue/cli-plugin-unit-jest": "^4.5.6",
...@@ -42,15 +43,18 @@ ...@@ -42,15 +43,18 @@
"@vue/eslint-config-prettier": "^6.0.0", "@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "^2.0.0-alpha.1", "@vue/test-utils": "^2.0.0-alpha.1",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"babel-jest": "^27.0.6",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.3", "eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^7.0.0-alpha.0", "eslint-plugin-vue": "^7.0.0-alpha.0",
"jest": "^27.0.6",
"less": "^3.0.4", "less": "^3.0.4",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"nodemon": "^2.0.7", "nodemon": "^2.0.7",
"pm2": "3.5.1", "pm2": "3.5.1",
"prettier": "^1.19.1" "prettier": "^1.19.1",
"vue3-jest": "^27.0.0-alpha.1"
}, },
"browserslist": [ "browserslist": [
"> 1%", "> 1%",
......
...@@ -44,7 +44,8 @@ exports.getWithdrawAudit = async ctx => { ...@@ -44,7 +44,8 @@ exports.getWithdrawAudit = async ctx => {
url, url,
method: "POST", method: "POST",
json: true, json: true,
body: ctx.request.body body: ctx.request.body,
timeout: 10000
} }
ctx.body = await req(ctx, opts) ctx.body = await req(ctx, opts)
} }
......
const request = require("request"); const request = require("request");
exports.httpReq = (ctx, opts) => { exports.httpReq = (ctx, opts) => {
opts.timeout = opts.timeout || 1000; opts.timeout = opts.timeout || 10000;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var time_start = +new Date(); var time_start = +new Date();
...@@ -18,7 +18,8 @@ exports.httpReq = (ctx, opts) => { ...@@ -18,7 +18,8 @@ exports.httpReq = (ctx, opts) => {
request(opts, (err, res, body) => { request(opts, (err, res, body) => {
console.info( console.info(
`[Api] httpReq (${opts.url}, user:[${opts.qs.op_cur_user `[Api] httpReq (${opts.url}, user:[${
opts.qs.op_cur_user
}]) spent: ${+new Date() - time_start}ms` }]) spent: ${+new Date() - time_start}ms`
); );
...@@ -31,5 +32,3 @@ exports.httpReq = (ctx, opts) => { ...@@ -31,5 +32,3 @@ exports.httpReq = (ctx, opts) => {
}); });
}); });
}; };
...@@ -10,24 +10,26 @@ ...@@ -10,24 +10,26 @@
</template> </template>
<script> <script>
import { fetchCurrentUser } from './service/user'; import { fetchCurrentUser } from "./service/user";
import { redirectToLogin } from './utils/util'; import { redirectToLogin } from "./utils/util";
export default { export default {
async mounted () { async created() {
console.log("master debug 2 !!!!!!") console.log("master debug 2 !!!!!!");
if (this.$store.state.permissions && this.$store.state.userInfo) return if (this.$store.state.permissions && this.$store.state.userInfo) return;
const { status, user } = await fetchCurrentUser(); const { status, user } = await fetchCurrentUser();
if (status === 'success') { if (status === "success") {
this.$store.commit('updateUserInfo', user); this.$store.commit("updateUserInfo", user);
this.$store.dispatch('updateUserPermission', { email: user.email }) this.$store.dispatch("updateUserPermission", { email: user.email });
// 无奈之举,后期需要重构到提现管理中
this.$store.dispatch("fetchPermission", {
appId: "merchant-op-auditing",
});
} else { } else {
redirectToLogin(); redirectToLogin();
} }
}, },
}; };
</script> </script>
<style lang="less" src="./global.less"></style> <style lang="less" src="./global.less"></style>
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<script> <script>
import { import {
get_role_info as reqGet_role_info, get_role_info as reqGet_role_info,
getAll_role_list as reqGetAll_role_list getAll_role_list as reqGetAll_role_list,
} from "../../service/role"; } from "../../service/role";
export default { export default {
name: "RoleDetail", name: "RoleDetail",
...@@ -82,7 +82,7 @@ export default { ...@@ -82,7 +82,7 @@ export default {
multiple: true, //设置为多选 multiple: true, //设置为多选
value: "id", //value值和哪个值绑定 value: "id", //value值和哪个值绑定
label: "desc", //label值和哪个值绑定 label: "desc", //label值和哪个值绑定
children: "sub_permissions" //children值和哪个值绑定 children: "sub_permissions", //children值和哪个值绑定
}, },
selectedOptions: [], selectedOptions: [],
permissionsAll: [], permissionsAll: [],
...@@ -95,17 +95,17 @@ export default { ...@@ -95,17 +95,17 @@ export default {
update_user_name: "", update_user_name: "",
create_time: "", create_time: "",
create_user_name: "", create_user_name: "",
role_account_list: [] role_account_list: [],
} },
}; };
}, },
mounted() { mounted() {
this.roleId = this.$route.query.roleId; this.roleId = this.$route.query.roleId;
let { email } = this.$store.state.userInfo; let { email } = this.$store.state.userInfo;
reqGetAll_role_list(email, this.appId).then(res => { reqGetAll_role_list(email, this.appId).then((res) => {
this.permissionsAll = res.permissions; this.permissionsAll = res.permissions;
}); });
reqGet_role_info(this.roleId, this.appId).then(res => { reqGet_role_info(this.roleId, this.appId).then((res) => {
const { const {
role_name, role_name,
role_status, role_status,
...@@ -114,7 +114,7 @@ export default { ...@@ -114,7 +114,7 @@ export default {
create_time, create_time,
create_user_name, create_user_name,
role_account_list, role_account_list,
permissions permissions,
} = res.result; } = res.result;
this.role_info_detail = { this.role_info_detail = {
role_name, role_name,
...@@ -123,7 +123,7 @@ export default { ...@@ -123,7 +123,7 @@ export default {
update_user_name, update_user_name,
create_time, create_time,
create_user_name, create_user_name,
role_account_list role_account_list,
}; };
this.editEchoData(permissions); this.editEchoData(permissions);
}); });
...@@ -135,18 +135,18 @@ export default { ...@@ -135,18 +135,18 @@ export default {
//遍历回显值selectedOptions //遍历回显值selectedOptions
editEchoData(permissions) { editEchoData(permissions) {
let selectData = []; let selectData = [];
permissions.map(item => { permissions.map((item) => {
let one = { id: item.id }; let one = { id: item.id };
if (item.sub_permissions) { if (item.sub_permissions) {
item.sub_permissions.map(info => { item.sub_permissions.map((info) => {
let selectId = [one.id, info.id]; let selectId = [one.id, info.id];
selectData.push(selectId); selectData.push(selectId);
}); });
} }
}); });
this.selectedOptions = selectData; this.selectedOptions = selectData;
} },
} },
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
...@@ -141,31 +141,33 @@ import { ...@@ -141,31 +141,33 @@ import {
getUpdate_role as reqGetUpdate_role, getUpdate_role as reqGetUpdate_role,
get_role_info as reqGet_role_info, get_role_info as reqGet_role_info,
getDelete_role as reqGetDelete_role, getDelete_role as reqGetDelete_role,
getAdd_role as reqGetAdd_role getAdd_role as reqGetAdd_role,
} from "../../service/role"; } from "../../service/role";
export default { export default {
name: "RoleList", name: "RoleList",
props: ["appId", "detailPath"], props: ["appId", "detailPath", "rolePermissionId"],
components: { components: {
page page,
}, },
computed: { computed: {
permission() { permission() {
let rolePermissionId = this.rolePermissionId || "role";
let appId = this.appId || "";
const modulePermissions = const modulePermissions =
this.$store.getters.moduleSubPermissions("role") || []; this.$store.getters.moduleSubPermissions(rolePermissionId, appId) || [];
return new Map(modulePermissions.map(ele => [ele.name, true])); return new Map(modulePermissions.map((ele) => [ele.name, true]));
} },
}, },
data() { data() {
return { return {
searchForm: { searchForm: {
roleName: "", roleName: "",
roleStatus: "" roleStatus: "",
}, },
formLabelWidth: "120px", formLabelWidth: "120px",
params: { params: {
page: 1, page: 1,
page_size: 20 page_size: 20,
}, },
totalNum: null, totalNum: null,
roleTitle: "", roleTitle: "",
...@@ -175,7 +177,7 @@ export default { ...@@ -175,7 +177,7 @@ export default {
multiple: true, //设置为多选 multiple: true, //设置为多选
value: "id", //value值和哪个值绑定 value: "id", //value值和哪个值绑定
label: "desc", //label值和哪个值绑定 label: "desc", //label值和哪个值绑定
children: "sub_permissions" //children值和哪个值绑定 children: "sub_permissions", //children值和哪个值绑定
}, },
selectedOptions: [], selectedOptions: [],
dialogVisible: false, dialogVisible: false,
...@@ -184,11 +186,11 @@ export default { ...@@ -184,11 +186,11 @@ export default {
role_info_detail: { role_info_detail: {
//详情非编辑项 //详情非编辑项
role_id: "", role_id: "",
role_name: "" role_name: "",
}, },
permissionsAll: [], permissionsAll: [],
currenPermissionsUpdate: [], currenPermissionsUpdate: [],
currentRolePrivilege: [] currentRolePrivilege: [],
}; };
}, },
beforeMount() { beforeMount() {
...@@ -212,12 +214,12 @@ export default { ...@@ -212,12 +214,12 @@ export default {
toRoleDetail(row) { toRoleDetail(row) {
this.$router.push({ this.$router.push({
path: this.detailPath, path: this.detailPath,
query: { roleId: row.role_id } query: { roleId: row.role_id },
}); });
}, },
getPermissionsAll() { getPermissionsAll() {
let { email } = this.$store.state.userInfo; let { email } = this.$store.state.userInfo;
reqGetAll_role_list(email, this.appId).then(res => { reqGetAll_role_list(email, this.appId).then((res) => {
this.permissionsAll = res.permissions; this.permissionsAll = res.permissions;
}); });
}, },
...@@ -228,9 +230,9 @@ export default { ...@@ -228,9 +230,9 @@ export default {
page, page,
page_size, page_size,
role_status: this.searchForm.roleStatus, role_status: this.searchForm.roleStatus,
role_name: this.searchForm.roleName role_name: this.searchForm.roleName,
}; };
reqGetRole_list(paramsRole_list, this.appId).then(res => { reqGetRole_list(paramsRole_list, this.appId).then((res) => {
this.managementList = res.result; this.managementList = res.result;
this.totalNum = res.count; this.totalNum = res.count;
}); });
...@@ -255,7 +257,7 @@ export default { ...@@ -255,7 +257,7 @@ export default {
this.$confirm(`${this.dialogText}是否继续?`, "提示", { this.$confirm(`${this.dialogText}是否继续?`, "提示", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning",
}) })
.then(() => { .then(() => {
if (type === "disable") { if (type === "disable") {
...@@ -267,23 +269,23 @@ export default { ...@@ -267,23 +269,23 @@ export default {
.catch(() => { .catch(() => {
this.$message({ this.$message({
type: "info", type: "info",
message: "已取消" message: "已取消",
}); });
}); });
}, },
//删除 //删除
delete(role_id) { delete(role_id) {
reqGetDelete_role(role_id, this.appId).then(res => { reqGetDelete_role(role_id, this.appId).then((res) => {
if (res.status == "success") this.getGetRole_list(); if (res.status == "success") this.getGetRole_list();
}); });
}, },
//角色详情数据 //角色详情数据
getRole_info_detail(type, role_id) { getRole_info_detail(type, role_id) {
reqGet_role_info(role_id, this.appId).then(res => { reqGet_role_info(role_id, this.appId).then((res) => {
const { role_id, role_name, permissions } = res.result; const { role_id, role_name, permissions } = res.result;
this.role_info_detail = { this.role_info_detail = {
role_id, role_id,
role_name role_name,
}; };
this.roleName = role_name; this.roleName = role_name;
// this.permissionsUpdate = permissions // this.permissionsUpdate = permissions
...@@ -306,10 +308,10 @@ export default { ...@@ -306,10 +308,10 @@ export default {
//遍历回显值selectedOptions //遍历回显值selectedOptions
editEchoData(permissions) { editEchoData(permissions) {
let selectData = []; let selectData = [];
permissions.map(item => { permissions.map((item) => {
let one = { id: item.id }; let one = { id: item.id };
if (item.sub_permissions) { if (item.sub_permissions) {
item.sub_permissions.map(info => { item.sub_permissions.map((info) => {
let selectId = [one.id, info.id]; let selectId = [one.id, info.id];
selectData.push(selectId); selectData.push(selectId);
}); });
...@@ -322,7 +324,7 @@ export default { ...@@ -322,7 +324,7 @@ export default {
if (row.role_status == 1) { if (row.role_status == 1) {
this.$message({ this.$message({
type: "info", type: "info",
message: "该条数据已启用" message: "该条数据已启用",
}); });
return false; return false;
} }
...@@ -333,7 +335,7 @@ export default { ...@@ -333,7 +335,7 @@ export default {
if (row.role_status == 2) { if (row.role_status == 2) {
this.$message({ this.$message({
type: "info", type: "info",
message: "该条数据已禁用" message: "该条数据已禁用",
}); });
return false; return false;
} }
...@@ -346,9 +348,9 @@ export default { ...@@ -346,9 +348,9 @@ export default {
role_name: role_name, role_name: role_name,
role_id, role_id,
role_status, role_status,
permissions permissions,
}; };
reqGetUpdate_role(paramsUpdate_role, this.appId).then(res => { reqGetUpdate_role(paramsUpdate_role, this.appId).then((res) => {
if (res.status === "success") { if (res.status === "success") {
this.dialogVisible = false; this.dialogVisible = false;
this.getGetRole_list(); this.getGetRole_list();
...@@ -356,7 +358,7 @@ export default { ...@@ -356,7 +358,7 @@ export default {
this.dialogVisible = false; this.dialogVisible = false;
this.$message({ this.$message({
type: "info", type: "info",
message: `${res.reason}` message: `${res.reason}`,
}); });
} }
}); });
...@@ -383,7 +385,7 @@ export default { ...@@ -383,7 +385,7 @@ export default {
if (!(this.roleName && checkRolePrivilege.length > 0)) { if (!(this.roleName && checkRolePrivilege.length > 0)) {
this.$message({ this.$message({
type: "error", type: "error",
message: "请完善信息" message: "请完善信息",
}); });
return false; return false;
} }
...@@ -408,16 +410,16 @@ export default { ...@@ -408,16 +410,16 @@ export default {
getAdd_role() { getAdd_role() {
let paramsAdd_role = { let paramsAdd_role = {
role_name: this.roleName, role_name: this.roleName,
permissions: this.currenPermissionsUpdate permissions: this.currenPermissionsUpdate,
}; };
reqGetAdd_role(paramsAdd_role, this.appId).then(res => { reqGetAdd_role(paramsAdd_role, this.appId).then((res) => {
this.dialogVisible = false; this.dialogVisible = false;
if (res.status === "success") { if (res.status === "success") {
this.getGetRole_list(); this.getGetRole_list();
} else { } else {
this.$message({ this.$message({
type: "info", type: "info",
message: `${res.reason}` message: `${res.reason}`,
}); });
} }
}); });
...@@ -427,13 +429,13 @@ export default { ...@@ -427,13 +429,13 @@ export default {
}, },
getSelectedOptions(selectedOptions) { getSelectedOptions(selectedOptions) {
let oldDataRule = []; let oldDataRule = [];
selectedOptions.forEach(el => { selectedOptions.forEach((el) => {
let oldObj = { let oldObj = {
id: el[0], id: el[0],
sub_permissions: [] sub_permissions: [],
}; };
let btnObj = { let btnObj = {
id: el[1] id: el[1],
}; };
oldObj.sub_permissions.push(btnObj); oldObj.sub_permissions.push(btnObj);
oldDataRule.push(oldObj); oldDataRule.push(oldObj);
...@@ -445,11 +447,11 @@ export default { ...@@ -445,11 +447,11 @@ export default {
newData.push(el); newData.push(el);
newObj[el.id] = true; newObj[el.id] = true;
} else { } else {
newData.forEach(el => { newData.forEach((el) => {
if (el.id === oldDataRule[i].id) { if (el.id === oldDataRule[i].id) {
el.sub_permissions = [ el.sub_permissions = [
...el.sub_permissions, ...el.sub_permissions,
...oldDataRule[i].sub_permissions ...oldDataRule[i].sub_permissions,
]; ];
} }
}); });
...@@ -457,8 +459,8 @@ export default { ...@@ -457,8 +459,8 @@ export default {
}); });
this.currentRolePrivilege = newData; this.currentRolePrivilege = newData;
this.currenPermissionsUpdate = newData; this.currenPermissionsUpdate = newData;
} },
} },
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
...@@ -114,17 +114,17 @@ import { ...@@ -114,17 +114,17 @@ import {
getUserList as reqGetUserList, getUserList as reqGetUserList,
getUserDetail as reqGetUserDetail, getUserDetail as reqGetUserDetail,
editUser as reqEditUser, editUser as reqEditUser,
createUser as reqCreateUser createUser as reqCreateUser,
} from "@/service/user"; } from "@/service/user";
export default { export default {
name: "UserList", name: "UserList",
props: ["appId"], props: ["appId", "userPermissionId"],
components: { components: {
page, page,
UserInfoModal, UserInfoModal,
UserInfoEditModal, UserInfoEditModal,
UserInfoNewModal UserInfoNewModal,
}, },
data() { data() {
return { return {
...@@ -135,7 +135,7 @@ export default { ...@@ -135,7 +135,7 @@ export default {
user_name: "", user_name: "",
user_email: "", user_email: "",
user_mobile: "", user_mobile: "",
user_status: "" user_status: "",
}, },
totalNum: 0, totalNum: 0,
userList: [], userList: [],
...@@ -143,30 +143,32 @@ export default { ...@@ -143,30 +143,32 @@ export default {
modalVisable: { modalVisable: {
info: false, info: false,
edit: false, edit: false,
new: false new: false,
}, },
curOperateMode: "new" curOperateMode: "new",
}; };
}, },
computed: { computed: {
permission() { permission() {
const appId = this.appId || "";
const userPermissionId = this.userPermissionId || "user";
const modulePermissions = const modulePermissions =
this.$store.getters.moduleSubPermissions("user") || []; this.$store.getters.moduleSubPermissions(userPermissionId, appId) || [];
console.log("Current page func-permissions:", modulePermissions); console.log("Current page func-permissions:", modulePermissions);
return new Map(modulePermissions.map(ele => [ele.name, true])); return new Map(modulePermissions.map((ele) => [ele.name, true]));
}, },
renderUserList() { renderUserList() {
const statusMap = new Map([ const statusMap = new Map([
[1, "启用"], [1, "启用"],
[2, "禁用"], [2, "禁用"],
[3, "删除"] [3, "删除"],
]); ]);
return this.userList.map(ele => { return this.userList.map((ele) => {
ele.user_status = statusMap.get(ele.user_status); ele.user_status = statusMap.get(ele.user_status);
return ele; return ele;
}); });
} },
}, },
beforeMount() { beforeMount() {
this.getUserList(); this.getUserList();
...@@ -187,12 +189,12 @@ export default { ...@@ -187,12 +189,12 @@ export default {
async setCurUserInfo(user_id) { async setCurUserInfo(user_id) {
const { code, result } = await reqGetUserDetail({ const { code, result } = await reqGetUserDetail({
appid: this.appId, appid: this.appId,
user_id user_id,
}); });
if (code === 0) { if (code === 0) {
this.curUserInfo = { this.curUserInfo = {
...result.user_info, ...result.user_info,
roles: result.role_list roles: result.role_list,
}; };
} else { } else {
ElMessage.error("获取用户信息出错!"); ElMessage.error("获取用户信息出错!");
...@@ -214,7 +216,7 @@ export default { ...@@ -214,7 +216,7 @@ export default {
}, },
openModal(key) { openModal(key) {
Object.keys(this.modalVisable).forEach(ele => { Object.keys(this.modalVisable).forEach((ele) => {
this.modalVisable[ele] = key === ele; this.modalVisable[ele] = key === ele;
}); });
}, },
...@@ -228,7 +230,7 @@ export default { ...@@ -228,7 +230,7 @@ export default {
user_mobile, user_mobile,
roles, roles,
user_status, user_status,
organization organization,
} = userInfo; } = userInfo;
let res = {}; let res = {};
...@@ -241,7 +243,7 @@ export default { ...@@ -241,7 +243,7 @@ export default {
is_sensitive_authority: parseInt(is_sensitive_authority), is_sensitive_authority: parseInt(is_sensitive_authority),
user_mobile, user_mobile,
role_id: roles, role_id: roles,
user_status: parseInt(user_status) user_status: parseInt(user_status),
}; };
res = await reqEditUser(editData, this.appId); res = await reqEditUser(editData, this.appId);
} else if (this.curOperateMode === "new") { } else if (this.curOperateMode === "new") {
...@@ -252,7 +254,7 @@ export default { ...@@ -252,7 +254,7 @@ export default {
user_mobile, user_mobile,
role_id: roles, role_id: roles,
user_status: parseInt(user_status), user_status: parseInt(user_status),
organization organization,
}; };
res = await reqCreateUser(newData, this.appId); res = await reqCreateUser(newData, this.appId);
} }
...@@ -283,7 +285,7 @@ export default { ...@@ -283,7 +285,7 @@ export default {
user_name: "", user_name: "",
user_email: "", user_email: "",
user_mobile: "", user_mobile: "",
user_status: "" user_status: "",
}; };
this.getUserList(); this.getUserList();
}, },
...@@ -300,7 +302,7 @@ export default { ...@@ -300,7 +302,7 @@ export default {
const { code, reason } = await reqEditUser( const { code, reason } = await reqEditUser(
{ {
user_status: 1, user_status: 1,
user_id user_id,
}, },
this.appId this.appId
); );
...@@ -317,7 +319,7 @@ export default { ...@@ -317,7 +319,7 @@ export default {
const { code, reason } = await reqEditUser( const { code, reason } = await reqEditUser(
{ {
user_status: 2, user_status: 2,
user_id user_id,
}, },
this.appId this.appId
); );
...@@ -327,8 +329,8 @@ export default { ...@@ -327,8 +329,8 @@ export default {
} else { } else {
ElMessage.error(reason); ElMessage.error(reason);
} }
} },
} },
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
......
<template> <template>
<div> <div>
<layout> 没有权限! </layout> 没有权限!
</div> </div>
</template> </template>
<script> <script>
import Layout from '@/layouts';
export default { export default {
components: {
Layout,
},
}; };
</script> </script>
......
import { render } from "@testing-library/vue";
import ExaminePage from "..";
import { getApplyList } from "@/service/Withdrawal/withdrawal";
import store from "@/store";
jest.mock("@/service/Withdrawal/withdrawal");
it("should not enable audition for people without such privilege", () => {
const $route = {
path: "/op/withdrawal/examine"
};
getApplyList.mockResolvedValue({
code: 0,
status: "success",
result: {
list: [
{
withdraw_apply_id: "21072711253403105009",
wallet_id: "21072214560673105003",
user_id: 510227177373,
amount: "6.00",
withdraw_apply_status: 0,
withdraw_audit_time: "2021-07-27 11:25:34",
refuse_reason: "",
audit_user_name: "",
create_time: "2021-07-27 11:25:34",
lately_amount: "0.00",
id: "21072711253403105009",
city_name: "简网员工",
lately_share: 0,
lately_download: 0,
history_share: 52,
history_download: 0,
history_download_keep: "0%",
status_text: "待审核"
}
],
count: 1
}
});
const { getByText } = render(ExaminePage, {
store,
global: {
mocks: {
$route,
$store: {
getters: {
moduleSubPermissions: jest.fn().mockReturnValue(true)
}
}
}
}
});
getByText("审核");
});
...@@ -37,7 +37,11 @@ ...@@ -37,7 +37,11 @@
<el-form inline class="search_condition"> <el-form inline class="search_condition">
<!-- 用户id --> <!-- 用户id -->
<el-form-item label="用户id"> <el-form-item label="用户id">
<el-input v-model="searchProps.user_id"></el-input> <el-input v-model="searchProps.user_id" @input="
searchProps.user_id = $event
.replace(/[^a-z0-9A-Z\u4e00-\u9fa5()()\\-]+/g, '')
.replace(/\s/g, '')
"></el-input>
</el-form-item> </el-form-item>
<el-button <el-button
type="primary" type="primary"
...@@ -47,12 +51,7 @@ ...@@ -47,12 +51,7 @@
> >
</el-form> </el-form>
<!-- 列表区 --> <!-- 列表区 -->
<el-table <el-table class="goods_list" :data="goodsList" border stripe>
class="goods_list"
:data="goodsList"
border
stripe
>
<el-table-column <el-table-column
label="提现用户" label="提现用户"
prop="user_id" prop="user_id"
...@@ -78,13 +77,23 @@ ...@@ -78,13 +77,23 @@
prop="lately_share" prop="lately_share"
align="center" align="center"
></el-table-column> ></el-table-column>
<el-table-column
label="近两天分享下载量"
prop="lately_download"
align="center"
></el-table-column>
<el-table-column <el-table-column
label="历史分享增长" label="历史分享增长"
prop="history_share" prop="history_share"
align="center" align="center"
></el-table-column> ></el-table-column>
<el-table-column <el-table-column
label="历史分享留存" label="历史分享下载量"
prop="history_download"
align="center"
></el-table-column>
<el-table-column
label="历史下载留存"
prop="history_download_keep" prop="history_download_keep"
align="center" align="center"
></el-table-column> ></el-table-column>
...@@ -107,7 +116,7 @@ ...@@ -107,7 +116,7 @@
></el-table-column> ></el-table-column>
<!-- 操作快捷键 --> <!-- 操作快捷键 -->
<el-table-column label="操作" align="center" fixed="right" width="200"> <el-table-column label="操作" align="center" fixed="right" width="200">
<template #default="scope"> <template v-slot:default="scope">
<el-button <el-button
type="text" type="text"
@click="handleDetail('look', scope.row.id)" @click="handleDetail('look', scope.row.id)"
...@@ -120,7 +129,10 @@ ...@@ -120,7 +129,10 @@
@click="handleDetail('audit', scope.row.id)" @click="handleDetail('audit', scope.row.id)"
>审核</el-button >审核</el-button
> >
<el-popconfirm title="确定解冻吗?" @confirm="handleFinzingFind(scope.row.id)"> <el-popconfirm
title="确定解冻吗?"
@confirm="handleFinzingFind(scope.row.id)"
>
<template #reference> <template #reference>
<el-button <el-button
type="text" type="text"
...@@ -129,7 +141,7 @@ ...@@ -129,7 +141,7 @@
> >
</template> </template>
</el-popconfirm> </el-popconfirm>
<!-- <el-button <!-- <el-button
type="text" type="text"
v-if="searchProps.withdraw_apply_status == '3'" v-if="searchProps.withdraw_apply_status == '3'"
...@@ -223,8 +235,8 @@ ...@@ -223,8 +235,8 @@
label="分享用户量" label="分享用户量"
width="120" width="120"
> >
<template #default="scope"> <template v-slot:default="scope">
<span>{{ "+" + scope.row.amount }}</span> <span>{{ scope ? "+" + scope.row.amount : null }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -267,9 +279,10 @@ import { ...@@ -267,9 +279,10 @@ import {
getWithdrawAudit, getWithdrawAudit,
getApplyDetail, getApplyDetail,
getFreezingFund, getFreezingFund,
getAll_role_list, getRolesForUser,
} from "../../../service/Withdrawal/withdrawal"; } from "@/service/Withdrawal/withdrawal";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { fetchCurrentUser } from "../../../service/user";
const TABS = { const TABS = {
pending: "0", pending: "0",
...@@ -304,7 +317,7 @@ export default { ...@@ -304,7 +317,7 @@ export default {
searchProps: { searchProps: {
user_id: "", //用户id user_id: "", //用户id
page: 1, page: 1,
count:0, count: 0,
page_size: 20, //每页条数 page_size: 20, //每页条数
status: TABS.pending, //状态 status: TABS.pending, //状态
}, },
...@@ -331,12 +344,44 @@ export default { ...@@ -331,12 +344,44 @@ export default {
created() { created() {
this.getApplyList(); this.getApplyList();
}, },
async mounted() {
const res = await this.getPermissionsAll();
if (!res) {
this.$router.push({ name: "Forbidden" });
return;
}
let withdrawlPermission = res.filter(
({ name }) => name === "withdrawal_audit"
);
if (withdrawlPermission.length === 0) {
// push to forbidden
this.$router.push({ name: "Forbidden" });
return;
}
console.log("withdrawlPermission", withdrawlPermission);
withdrawlPermission = withdrawlPermission[0];
// judge subpermission
let subpermissions = withdrawlPermission.sub_permissions.filter(
({ name }) => name === "show"
);
if (subpermissions.length === 0) {
this.$router.push({ name: "Forbidden" });
}
},
methods: { methods: {
async getPermissionsAll() { async getPermissionsAll() {
let { email } = this.$store.state.userInfo; // 不能够信赖 store 中的 email,无法知道全局中的 fetchCurrentUser 处理完毕
const res = await getAll_role_list(email); // 是一个重构的点
const { user } = await fetchCurrentUser();
const res = await getRolesForUser(user.email);
this.permissions = res; this.permissions = res;
return res;
}, },
// tab切换 // tab切换
handleTabChange() { handleTabChange() {
this.searchProps.page = 0; this.searchProps.page = 0;
...@@ -403,7 +448,7 @@ export default { ...@@ -403,7 +448,7 @@ export default {
//获取黑名单 //获取黑名单
handleBlackList(action) { handleBlackList(action) {
const {id, user_id, wallet_id } = this.dialogData.showData; const { id, user_id, wallet_id } = this.dialogData.showData;
const params = { const params = {
id, id,
user_id, user_id,
...@@ -473,8 +518,8 @@ export default { ...@@ -473,8 +518,8 @@ export default {
showMode: "audit", //判断是审核还是查看 showMode: "audit", //判断是审核还是查看
}), }),
(this.award = ""), //奖励明细 (this.award = ""), //奖励明细
(this.outerVisible = false) //外层弹框 (this.outerVisible = false); //外层弹框
}, },
}, },
computed: { computed: {
isAllowedToAudit() { isAllowedToAudit() {
...@@ -485,22 +530,20 @@ export default { ...@@ -485,22 +530,20 @@ export default {
const WITHDRAWAL_PERMISSION_ID = 10; const WITHDRAWAL_PERMISSION_ID = 10;
const withdrawlPermission = this.permissions.filter( let withdrawlPermission = this.permissions.filter(
(item) => item.id === WITHDRAWAL_PERMISSION_ID (item) => item.id === WITHDRAWAL_PERMISSION_ID
); );
// 无此模块权限 // 无此模块权限
if (!withdrawlPermission) { if (withdrawlPermission.length === 0) {
return false; return false;
} }
const AUDIT_PERMSSION_ID = 14; const AUDIT_PERMSSION_ID = 14;
const auditPermission = withdrawlPermission[0].sub_permissions.filter(
const auditPermission = withdrawlPermission.filter(
(item) => item.id === AUDIT_PERMSSION_ID (item) => item.id === AUDIT_PERMSSION_ID
); );
return !!auditPermission; return auditPermission.length !== 0;
}, },
}, },
}; };
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<role-list <role-list
appId="merchant-op-auditing" appId="merchant-op-auditing"
detailPath="/op/withdrawal/roleRoleDetail" detailPath="/op/withdrawal/roleRoleDetail"
rolePermissionId="role_management"
></role-list> ></role-list>
</layout> </layout>
</template> </template>
......
<template> <template>
<layout> <layout>
<user-list appId="merchant-op-auditing"></user-list> <user-list
appId="merchant-op-auditing"
userPermissionId="user_management"
></user-list>
</layout> </layout>
</template> </template>
......
...@@ -4,14 +4,17 @@ const headerConfig = [ ...@@ -4,14 +4,17 @@ const headerConfig = [
path: "/op/withdrawal/examine" path: "/op/withdrawal/examine"
}, },
{ {
path: '/op/withdrawal/roleManageRole', path: "/op/withdrawal/roleManageRole",
name: '角色管理' name: "角色管理",
requireAuthentication: true,
requiredPermission: "role_management"
}, },
{ {
path: '/op/withdrawal/user', path: "/op/withdrawal/user",
name: '用户管理' name: "用户管理",
requireAuthentication: true,
requiredPermission: "user_management"
} }
]; ];
export default headerConfig; export default headerConfig;
\ No newline at end of file
...@@ -12,16 +12,13 @@ ...@@ -12,16 +12,13 @@
unique-opened unique-opened
> >
<el-menu-item <el-menu-item
v-for="item in headerConfig" v-for="item in visibleMenuItems"
:index="item.path" :index="item.path"
:key="item.path" :key="item.path"
> >
{{ item.name }} {{ item.name }}
</el-menu-item> </el-menu-item>
<el-menu-item <el-menu-item key="usermenu" class="user-menu">
key="usermenu"
class="user-menu"
>
<user></user> <user></user>
</el-menu-item> </el-menu-item>
</el-menu> </el-menu>
...@@ -35,22 +32,42 @@ import User from "./User.vue"; ...@@ -35,22 +32,42 @@ import User from "./User.vue";
export default { export default {
name: "PageHeader", name: "PageHeader",
components: { components: {
User User,
}, },
data () { data() {
return { return {
headerConfig headerConfig,
}; };
}, },
computed: { computed: {
activeMenu () { activeMenu() {
return this.$route.path; return this.$route.path;
} },
visibleMenuItems() {
const visibleMenuItems = this.headerConfig.filter((item) => {
if (!item.requireAuthentication) {
return true;
}
if (this.hasPermission(item.requiredPermission)) {
return true;
}
return false;
});
return visibleMenuItems;
},
},
beforeMount() {},
methods: {
hasPermission(permissionId) {
return (
this.$store.getters.moduleSubPermissions(
permissionId,
"merchant-op-auditing"
).length !== 0
);
},
}, },
beforeMount () { },
methods: {}
}; };
</script> </script>
<style lang="less"> <style lang="less"></style>
</style>
...@@ -7,19 +7,26 @@ const withdrawalRoutes = [ ...@@ -7,19 +7,26 @@ const withdrawalRoutes = [
{ {
path: "/op/withdrawal/examine", path: "/op/withdrawal/examine",
name: "Examine", name: "Examine",
component: () => import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Examine"), component: () =>
import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Examine")
}, },
//用户管理 //用户管理
{ {
path: "/op/withdrawal/user", path: "/op/withdrawal/user",
name: "User", name: "User",
component: () => import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/User/userList"), component: () =>
import(
/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/User/userList"
)
}, },
//角色管理 //角色管理
{ {
path: "/op/withdrawal/roleAddRole", path: "/op/withdrawal/roleAddRole",
name: "AddRole", name: "AddRole",
component: () => import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/add-role"), component: () =>
import(
/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/add-role"
),
meta: { meta: {
requireAuth: true, requireAuth: true,
keepAlive: true keepAlive: true
...@@ -28,7 +35,10 @@ const withdrawalRoutes = [ ...@@ -28,7 +35,10 @@ const withdrawalRoutes = [
{ {
path: "/op/withdrawal/roleManageRole", path: "/op/withdrawal/roleManageRole",
name: "ManageRole", name: "ManageRole",
component: () => import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/manage-role"), component: () =>
import(
/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/manage-role"
),
meta: { meta: {
requireAuth: true, requireAuth: true,
keepAlive: true keepAlive: true
...@@ -37,11 +47,11 @@ const withdrawalRoutes = [ ...@@ -37,11 +47,11 @@ const withdrawalRoutes = [
{ {
path: "/op/withdrawal/roleRoleDetail", path: "/op/withdrawal/roleRoleDetail",
name: "RoleDetail", name: "RoleDetail",
component: () => import(/* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/role-detail"), component: () =>
meta: { import(
keepAlive: true /* webpackChunkName: "Withdrawal" */ "@/pages/Withdrawal/Role/role-detail"
} )
}, }
]; ];
export default withdrawalRoutes; export default withdrawalRoutes;
\ No newline at end of file
...@@ -6,23 +6,28 @@ const getParams = (p = {}) => { ...@@ -6,23 +6,28 @@ const getParams = (p = {}) => {
}; };
// 获取提现审核列表 // 获取提现审核列表
export async function getApplyList (params) { export async function getApplyList(params) {
const res = await axios.get("/api/v1/get_withdrawal_apply_list", {params: getParams(params)}); const res = await axios.get("/api/v1/get_withdrawal_apply_list", {
return res; params: getParams(params)
} });
// 黑名单,冻结用户 return res;
export async function getBlackList (params) { }
const res = await axios.post("/api/v1/get_withdrawal_black_list" ,getParams(params)); // 黑名单,冻结用户
return res; export async function getBlackList(params) {
} const res = await axios.post(
"/api/v1/get_withdrawal_black_list",
getParams(params)
);
return res;
}
// 获取订单审核--通过,拒绝 // 获取订单审核--通过,拒绝
export async function getWithdrawAudit (params) { export async function getWithdrawAudit(params) {
const res = await axios.post("/api/v1/get_withdraw_audit", getParams(params)); const res = await axios.post("/api/v1/get_withdraw_audit", getParams(params));
return res; return res;
} }
// 获取提现失败冻结 // 获取提现失败冻结
export async function getFreezingFund (params) { export async function getFreezingFund(params) {
const res = await axios.post("/api/v1/get_freezing_fund",getParams(params)); const res = await axios.post("/api/v1/get_freezing_fund", getParams(params));
return res; return res;
} }
// 获取提现审核详情 // 获取提现审核详情
...@@ -33,7 +38,7 @@ export async function getApplyDetail(params) { ...@@ -33,7 +38,7 @@ export async function getApplyDetail(params) {
return res; return res;
} }
//权限列表 //权限列表
export async function getAll_role_list(user_email) { export async function getRolesForUser(user_email) {
const res = await axios.post( const res = await axios.post(
"/api/v1/merchant/authority/get_role_list?appid=merchant-op-auditing", "/api/v1/merchant/authority/get_role_list?appid=merchant-op-auditing",
{ {
......
import axios from '../utils/request'; import axios from "../utils/request";
// import qs from 'qs'; // import qs from 'qs';
//角色列表 //角色列表
export async function getRole_list (parmasRole_list, appid) { export async function getRole_list(parmasRole_list, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/role_list", url: "/api/v1/merchant/authority/role_list",
...@@ -13,7 +13,7 @@ export async function getRole_list (parmasRole_list, appid) { ...@@ -13,7 +13,7 @@ export async function getRole_list (parmasRole_list, appid) {
return await axios(opts); return await axios(opts);
} }
//添加角色 //添加角色
export async function getAdd_role (parmasAdd_role, appid) { export async function getAdd_role(parmasAdd_role, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/add_role", url: "/api/v1/merchant/authority/add_role",
...@@ -25,7 +25,7 @@ export async function getAdd_role (parmasAdd_role, appid) { ...@@ -25,7 +25,7 @@ export async function getAdd_role (parmasAdd_role, appid) {
// return res; // return res;
} }
//角色编辑 //角色编辑
export async function getUpdate_role (parmasUpdate_role, appid) { export async function getUpdate_role(parmasUpdate_role, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/update_role", url: "/api/v1/merchant/authority/update_role",
...@@ -37,7 +37,7 @@ export async function getUpdate_role (parmasUpdate_role, appid) { ...@@ -37,7 +37,7 @@ export async function getUpdate_role (parmasUpdate_role, appid) {
// return res; // return res;
} }
//角色详情 //角色详情
export async function get_role_info (role_id, appid) { export async function get_role_info(role_id, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/get_role_info", url: "/api/v1/merchant/authority/get_role_info",
...@@ -52,7 +52,7 @@ export async function get_role_info (role_id, appid) { ...@@ -52,7 +52,7 @@ export async function get_role_info (role_id, appid) {
// return res.result; // return res.result;
} }
//角色删除 //角色删除
export async function getDelete_role (role_id, appid) { export async function getDelete_role(role_id, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/delete_role", url: "/api/v1/merchant/authority/delete_role",
...@@ -68,7 +68,7 @@ export async function getDelete_role (role_id, appid) { ...@@ -68,7 +68,7 @@ export async function getDelete_role (role_id, appid) {
} }
//权限列表 //权限列表
export async function getAll_role_list (user_email, appid) { export async function getAll_role_list(user_email, appid) {
const opts = { const opts = {
method: "post", method: "post",
url: "/api/v1/merchant/authority/get_role_list", url: "/api/v1/merchant/authority/get_role_list",
......
import { createStore } from "vuex"; import { createStore } from "vuex";
import { getPermissions } from '@/service/user'; import { getPermissions } from "@/service/user";
import { PERMISSIONNAME_PAGEMODULE } from '../config/pageconfig' import { PERMISSIONNAME_PAGEMODULE } from "../config/pageconfig";
import { getRolesForUser } from "@/service/Withdrawal/withdrawal";
export default createStore({ export default createStore({
state: { state: {
permissions: null, permissions: null,
userInfo: null userInfo: null,
permissionsForApp: {}
}, },
mutations: { mutations: {
updateUserPermission (state, payload) { updateUserPermission(state, payload) {
state.permissions = payload; state.permissions = payload;
}, },
updateUserInfo (state, payload) { updateUserInfo(state, payload) {
state.userInfo = payload; state.userInfo = payload;
},
updatePermissionForApp(state, payload) {
const { appId, permissions } = payload;
state.permissionsForApp = state.permissionsForApp || {};
state.permissionsForApp[appId] = permissions;
} }
}, },
actions: { actions: {
async updateUserPermission ({ commit }, payload) { async updateUserPermission({ commit }, payload) {
const { permissions = [] } = await getPermissions(payload.email); const { permissions = [] } = await getPermissions(payload.email);
console.log("VUEX action updateUserPermission::", permissions); console.log("VUEX action updateUserPermission::", permissions);
commit('updateUserPermission', permissions) commit("updateUserPermission", permissions);
},
async fetchPermission({ commit }, { email, appId }) {
if (appId === "merchant-op-auditing") {
const permissions = await getRolesForUser(email);
if (!permissions) {
return;
}
const permissionMap = permissions.reduce((prev, permission) => {
prev[permission.name] = permission;
return prev;
}, {});
commit("updatePermissionForApp", { appId, permissions: permissionMap });
return;
}
console.error("无 appId 注册", appId);
} }
}, },
modules: {}, modules: {},
...@@ -29,19 +52,33 @@ export default createStore({ ...@@ -29,19 +52,33 @@ export default createStore({
subPermissions: state => { subPermissions: state => {
const permissionCol = {}; const permissionCol = {};
(state.permissions || []).forEach(element => { (state.permissions || []).forEach(element => {
PERMISSIONNAME_PAGEMODULE[element.name] && (permissionCol[PERMISSIONNAME_PAGEMODULE[element.name]] = element.sub_permissions) PERMISSIONNAME_PAGEMODULE[element.name] &&
(permissionCol[PERMISSIONNAME_PAGEMODULE[element.name]] =
element.sub_permissions);
}); });
return permissionCol; return permissionCol;
}, },
/** /**
* *
* @param {*} module 模块名,可选值: enterprise, lifeNo, role, user * @param {*} module 模块名,可选值: enterprise, lifeNo, role, user
* @returns * @returns
*/ */
moduleSubPermissions: (state) => (module) => { moduleSubPermissions: state => (module, appId = "") => {
if (appId !== "") {
if (!state.permissionsForApp[appId]) {
return [];
}
if (!state.permissionsForApp[appId][module]) {
return [];
}
return state.permissionsForApp[appId][module].sub_permissions;
}
const permissionCol = {}; const permissionCol = {};
(state.permissions || []).forEach(element => { (state.permissions || []).forEach(element => {
PERMISSIONNAME_PAGEMODULE[element.name] && (permissionCol[PERMISSIONNAME_PAGEMODULE[element.name]] = element.sub_permissions) PERMISSIONNAME_PAGEMODULE[element.name] &&
(permissionCol[PERMISSIONNAME_PAGEMODULE[element.name]] =
element.sub_permissions);
}); });
return permissionCol[module]; return permissionCol[module];
} }
......
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