Commit b67fded9 authored by GuanHua's avatar GuanHua
parents b6d96c07 0e85b7a7
......@@ -24,4 +24,6 @@
config/base.config.json
/src/services/index.ts
src/global/config/global.d.ts
src/services/*Api.ts
.vscode
......@@ -30,11 +30,7 @@ const serviceConfig = {
useType: {
url: '/member/menu/register/type',
method: 'get'
},
useDetail: {
url: '/member/menu/register/detail',
method: 'get'
},
}
},
//初始化会员支付策略配置
payConfig:{
......@@ -52,19 +48,46 @@ const serviceConfig = {
// 批量组装接口
async function batchAxiosHttps() {
const asyncHttpQueue = deepClone(serviceConfig)
const httpErrorQueue = []
const serverErrorQueue = []
console.log('\n')
for (const item in serviceConfig) {
if(JSON.stringify(item) !== '{}'){
for (const subItem in serviceConfig[item]) {
for (const subItem in serviceConfig[item]) {
try {
const data = await axios(serviceConfig[item][subItem])
asyncHttpQueue[item][subItem] = data.data.data
// 当接口出错时 不写入json文件
if (data.data.code === 1000) {
asyncHttpQueue[item][subItem] = data.data.data
} else {
serverErrorQueue.push({ ...asyncHttpQueue[item][subItem], ...data.data})
// 默认置为null
asyncHttpQueue[item][subItem] = null
}
} catch(err) {
console.log(serviceConfig[item][subItem].url)
console.log(err.response.data)
httpErrorQueue.push({...serviceConfig[item][subItem], ...err.response.data})
}
}
}
}
if (httpErrorQueue.length > 0) {
console.log('\n网络错误\n')
// 可在此做日志收集
console.log(httpErrorQueue)
}
if (serverErrorQueue.length > 0) {
console.log('接口服务错误\n')
// 可在此做日志收集
console.log(serverErrorQueue)
}
if (httpErrorQueue.length > 0 || serverErrorQueue.length > 0) {
// 退出构建
console.log('\n脚本构建失败!!!!!!')
// 终止当前进程
process.exit(1)
}
return isDemo ? Object.assign(asyncHttpQueue, await demoFetch()) : asyncHttpQueue
}
......
......@@ -16,9 +16,13 @@ import queryString from 'query-string';
setup();
let extraRoutes: never[] = [];
// 与用户登录相关路由
const userLoginLists = [
'/login',
]
const whiteLists = [
'/',
'/login',
...userLoginLists,
'/noAuth'
]
/**
......@@ -54,11 +58,7 @@ export function render(oldRender:Function) {
PublicApi.getMemberManageLoginReget().then(res => {
const { data, code } = res
if (code === 1000) {
setAuth({
memberId: data.memberId,
userId: data.userId,
token: data.token
})
setAuth(data)
setRouters(data.urls)
} else {
removeAuth()
......@@ -88,12 +88,16 @@ export function onRouteChange({ routes, matchedRoutes, location, action }) {
return;
}
if (whiteLists.includes(location.pathname)) return;
const routeAuthUrls = getRouters()
// 是否登录
if (getAuth()) {
const { query, pathname } = location
const routeAuthUrls = getRouters()
if (userLoginLists.includes(pathname)) {
// 当登录过, 并且尝试访问登录相关页面, 需重定向到首页
history.replace('/memberCenter/home')
return ;
}
// 固定配置, 出现此参数说明需携带参数校验权限路由
if (query.page_type && routeAuthUrls.find(authPath => {
const parseUrl = queryString.parseUrl(authPath)
......@@ -111,7 +115,13 @@ export function onRouteChange({ routes, matchedRoutes, location, action }) {
// 无权限访问时
history.replace('/noAuth')
} else {
history.replace('/login')
// 未登录
if (whiteLists.includes(location.pathname)) {
// 访问路由在白名单里
} else {
history.replace('/login')
}
}
}
......
......@@ -15,12 +15,13 @@ const ModalTable:React.FC<ModalTableProps> = (props) => {
const { width = 704,modalTitle, confirm, cancel, visible, currentRef, ...resetTable } = props
const selfRef = currentRef || useRef<any>({})
useEffect(() => {
if (!visible) {
if (visible) {
// 重新开启时需reload接口
selfRef.current.reload && selfRef.current.reload()
} else {
selfRef.current.resetField && selfRef.current.resetField({
validate: false
})
// 重新开启时需reload接口
selfRef.current.reload && selfRef.current.reload()
}
}, [visible, selfRef.current])
return (
......
......@@ -67,7 +67,7 @@ export const createTreeActions = () => {
setSelectKeys(){},
setExpandedKeys(){},
getParentPath(id){return ''},
getParent(id){return null}
getParent(id){console.log('not init');return null}
}
return actions
}
......@@ -163,12 +163,11 @@ const TabTree:React.FC<TabTreeProps> = (props) => {
const data = transformSingleTitle(deepClone(treeData), selectKey, checkable, disabled, toolsRender, customKey, customTitle)
// 重写选择方法, 只有在开启多选的时候才会启用
const checkedKeys = findTreeKeys(treeData)
const checkedKeys = findTreeKeys(treeData, 'id')
const { selected, select,setSelected, unSelect, allSelected, unSelectAll, selectAll } = useSelections(
checkedKeys,
[]
);
useEffect(() => {
if (getMenuSelectData) {
getMenuSelectData().then(res => {
......@@ -208,7 +207,8 @@ const TabTree:React.FC<TabTreeProps> = (props) => {
const reductData = treeReduction(treeData)
const targetInfo = reductData[id]
const parentInfo = reductData[targetInfo.parentId]
return parentInfo || null
// fixbug 当选中根节点下的节点时, 由于无parentId, 需自动补充0
return parentInfo || {id: 0}
}
}
......
......@@ -13,6 +13,30 @@ export enum TEMPLATE_TYPE_TEXT {
goods = 'goods',
chennel = 'chennel'
}
// 商城类型
export const SHOP_TYPES = [
{
id: 1,
name: "企业商城"
},
{
id: 2,
name: "积分商城"
},
{
id: 3,
name: "渠道商城"
},
{
id: 4,
name: "渠道自有商城"
},
{
id: 5,
name: "渠道积分商城"
},
]
// 本地环境跳过权限校验
export const isDev = process.env.NODE_ENV === "development"
// export const isDev = false
......
export interface MemberType {
id: number;
typeName: string;
}
export interface BusinessType {
id: number;
typeName: string;
}
export interface UseType {
memberType: MemberType[];
businessType: BusinessType[];
}
export interface UserRegister {
useType: UseType;
useDetail?: any;
}
export interface RuleConfiguration {
value: number;
label: string;
platformType: number;
}
export interface PayWayResponse {
payType: number;
value: number;
label: string;
}
export interface PayInitializeConfig {
payType: number;
ruleConfigurations: RuleConfiguration[];
payWayResponses: PayWayResponse[];
}
export interface PayPlatformPayConfig {
id: number;
payType: number;
way: string;
isPitchOn: number;
}
export interface PayConfig {
payInitializeConfig: PayInitializeConfig[];
payPlatformPayConfig: PayPlatformPayConfig[];
}
export interface CountryList {
name: string;
key: string;
icon: string;
}
export interface Children {
code: string;
}
export interface MenuList {
code: string;
children: Children[];
}
export interface Global {
logo: string;
countryList: CountryList[];
menuList: MenuList[];
}
export interface RootObject {
userRegister: UserRegister;
payConfig: PayConfig;
global: Global;
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ import { Link, history } from 'umi'
import { Menu, Dropdown } from 'antd'
import { CaretDownOutlined } from '@ant-design/icons'
import styles from './index.less'
import { removeAuth } from '@/utils/auth'
import { removeAuth, getAuth } from '@/utils/auth'
const RightContent: React.FC<{}> = (props) => {
......@@ -22,7 +22,7 @@ const RightContent: React.FC<{}> = (props) => {
</Menu>
);
const userInfo = getAuth()
return <div className={styles.lxLayoutRight}>
<Link to="/home" className={styles.lxLink}>返回首页</Link>
......@@ -30,7 +30,7 @@ const RightContent: React.FC<{}> = (props) => {
<div className={styles.avatarWrap}>
<div className={styles.avatar}></div>
<div className="ant-dropdown-link" onClick={e => e.preventDefault()}>
<span>Admin</span>
<span>{userInfo?.name || '未知用户'}</span>
<CaretDownOutlined />
</div>
</div>
......
......@@ -66,7 +66,9 @@ const UserSystem: React.FC<{}> = () => {
},
{
title: '所属机构',
//@todo 需要添加字段
dataIndex: 'orgName',
align: 'center',
key: 'orgName'
},
{
title: '绑定手机号码',
......
......@@ -118,6 +118,7 @@ const AddUser: React.FC<{}> = () => {
align: 'center',
dataIndex: 'remark',
key: 'remark',
ellipsis: true
}
]
......
......@@ -81,11 +81,7 @@ class Index extends Component<{}, IndexState> {
console.log('Received values of form: ', values);
PublicApi.postMemberManageLogin(values).then(res => {
const { data } = res
setAuth({
memberId: data.memberId,
userId: data.userId,
token: data.token
})
setAuth(data)
setRouters(data.urls)
window.location.href = '/home'
}).catch(error => {
......
/*
* @Author: LeeJiancong
* @Date: 2020-07-22 09:54:50
* @LastEditors: LeeJiancong
* @LastEditTime: 2020-07-22 10:23:38
*/
import * as Api from './index'
import request from '@/utils/request'
import * as LogisticsApi from './LogisticsApi'
import * as PassApi from './PassApi'
import * as WarehouseApi from './WarehouseApi'
import * as MemberApi from './MemberApi'
import * as ProductApi from './ProductApi'
import * as TemplateApi from './TemplateApi'
import * as PayApi from './PayApi'
import * as SearchApi from './SearchApi'
import * as OrderApi from './OrderApi'
/**
* 可在这里写入自定义的接口
......@@ -15,4 +16,14 @@ export const CustomApi = {
}
// 公共的接口,从yapi拉下
export const PublicApi = Api
export const PublicApi = {
...LogisticsApi,
...PassApi,
...WarehouseApi,
...MemberApi,
...ProductApi,
...TemplateApi,
...PayApi,
...SearchApi,
...OrderApi,
}
import { isDev } from '@/constants'
import { PublicApi } from '@/services/api'
import { GetMemberManageLoginRegetResponse } from '@/services'
export interface AuthInfo {
userId: number,
memberId: number,
token: string
token: string,
name: string,
account: string,
}
export const setAuth = (info: AuthInfo) => {
export const setAuth = (info: GetMemberManageLoginRegetResponse) => {
window.localStorage.setItem('auth', JSON.stringify(info))
}
......
......@@ -56,10 +56,12 @@ const baseRequest = extend({
// 请求拦截器
baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit): { url: string, options: RequestOptionsInit } => {
// 判断是否有权限
const loginAfterHeaders = getAuth()
const { userId, memberId, token } = getAuth() || {}
const headers = {
...options.headers,
...loginAfterHeaders
userId,
memberId,
token
}
return {
// 前缀如果已经带上api, 跳过自动补前缀
......
/*
* @Author: LeeJiancong
* @Date: 2020-08-04 16:22:03
* @LastEditors: LeeJiancong
* @LastEditTime: 2020-08-07 14:38:56
*/
import { Config } from 'god-yapi2ts'
const tokens = [
'b063a0a29fb1a570d9f00eaabbdd8ccfe8e6e10e24739441990cc1098e79b601', // 业务中台管理平台
'7c8f235d95f6224ceb97c4d832b09658f9a75fb8721a95699b230af0733d7fa4', // 仓库服务
'8d14d945507d1f8cd89afe139ca6d111bbad25f702fafe0aec59d3c9cd2e0ffe', // 物流服务
'3a46198c5b97ac7147e5b07ad2dff5ac5c93c1afed47e1911961db87149e6ebf', // 商户会员管理服务
'efe99e20ed1375dc0db3e809e4fc7692f42ecebaf60cd77e65c50ed65d6ba6c4', // 商品服务
'7ec923520215c7e2f771867cb4d29cafbf823daf0fb2d3d9fa70b57a523c8bfb', // 页面模板
'11966e602e6ab7dd26b7495cad2a0f231b7c0253ce4b959a21612cf5a323150c', // 支付服务
const tokenList = [
{ name: 'Pass', token: 'b063a0a29fb1a570d9f00eaabbdd8ccfe8e6e10e24739441990cc1098e79b601' }, // 业务中台管理平台
{ name: 'Warehouse', token: '7c8f235d95f6224ceb97c4d832b09658f9a75fb8721a95699b230af0733d7fa4' }, // 仓库服务
{ name: 'Logistics', token: '8d14d945507d1f8cd89afe139ca6d111bbad25f702fafe0aec59d3c9cd2e0ffe' }, // 物流服务
{ name: 'Member', token: '3a46198c5b97ac7147e5b07ad2dff5ac5c93c1afed47e1911961db87149e6ebf' }, // 商户会员管理服务
{ name: 'Product', token: 'efe99e20ed1375dc0db3e809e4fc7692f42ecebaf60cd77e65c50ed65d6ba6c4' }, // 商品服务
{ name: 'Template', token: '7ec923520215c7e2f771867cb4d29cafbf823daf0fb2d3d9fa70b57a523c8bfb' }, // 店铺模板服务
{ name: 'Pay', token: 'c789e0e56ee8a8cc2fbd85f930eb2928c58fc1014583c6643acf29cff954da49' }, // 支付服务
{ name: 'Search', token: 'ca19f532efba91f7773cbfbd526b798c6ac83df670071e97d72c50dca1d53a48' }, // 搜索服务
{ name: 'Order', token: '5de0aaeaac12c8d911d86dada6cd128993e34cd6e13135fa79246aa5979a2bcd' }, //订单服务
]
const genMap = (tokens) => {
return tokens.map(v => {
return {
token: v,
const getConfigMap = (tokens) => tokens.map(v => ({
serverUrl: 'http://10.0.0.25:4000/',
typesOnly: false,
reactHooks: {
enabled: false,
},
outputFilePath: `src/services/${v.name}Api.ts`,
requestFunctionFilePath: 'request.ts',
dataKey: 'data',
projects: [
{
token: v.token,
categories: [
{
id: 0,
......@@ -29,21 +31,7 @@ const genMap = (tokens) => {
},
]
}
})
}
const config: Config = [
{
serverUrl: 'http://10.0.0.25:4000/',
typesOnly: false,
reactHooks: {
enabled: false,
},
outputFilePath: 'src/services/index.ts',
requestFunctionFilePath: 'request.ts',
dataKey: 'data',
projects: genMap(tokens),
},
]
],
}))
export default config
\ No newline at end of file
export default getConfigMap(tokenList)
\ 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