添加 dic 组件,select 和 value text

pull/1/head
sin 2019-03-07 21:56:05 +08:00
parent 03f6b2b82c
commit 657eb1c980
61 changed files with 432 additions and 0 deletions

View File

@ -1,4 +1,6 @@
/* eslint-disable */
import mockjs from 'mockjs';
import { resultBody } from './mock-comment';
import adminMenu from './geographic/admin-menu.json';
import adminMenuAll from './geographic/admin-menu-all.json';
import adminUrls from './geographic/admin-urls';
@ -25,9 +27,28 @@ function getQueryRole(req, res) {
return res.json(roleQuery);
}
function getDictionaryKeys(req, res) {
const values = mockjs.mock({
'list|5': [{ 'value|+1': 0, text: '@city' }],
});
return res.json(resultBody(values));
}
function getDictionaryText(req, res) {
const values = mockjs.mock({
text: '@city',
});
return res.json(resultBody(values));
}
export default {
'GET /admin-api/admins/resource/admin_menu_tree': getAdminMenuAll,
'GET /admin-api/admins/resource/admin_url_list': getAdminUrls,
'GET /admin-api/admins/resource/tree': getResourceTree,
'GET /admin-api/admins/role/page': getQueryRole,
'GET /admin-api/admins/admin/page': getQueryRole,
'GET /admin-api/admins/dictionary/getList': getDictionaryKeys,
'GET /admin-api/admins/dictionary/queryText': getDictionaryText,
};

View File

@ -0,0 +1,13 @@
// 常用,公共 mock
export function resultBody(result, code, message) {
return {
code: code || 0,
message: message || '',
...(result || null),
};
}
export default {
resultBody,
};

View File

@ -0,0 +1,13 @@
import * as React from 'react';
import { Select } from 'antd';
export interface DictionaryObject {
text?: string;
value?: string | number | boolean;
}
export interface IDictionarySelectProps extends Select {
list?: DictionaryObject[];
}
export default class DictionarySelectD extends React.Component<IDictionarySelectProps, any> {}

View File

@ -0,0 +1,20 @@
import React, { PureComponent } from 'react';
import { Select } from 'antd';
export default class DictionarySelect extends PureComponent {
renderOptions() {
const { list } = this.props;
return list.map(item => {
return (
<Select.Option key={item.value} value={item.value}>
{item.text}
</Select.Option>
);
});
}
render() {
const options = this.renderOptions();
return <Select {...this.props}>{options}</Select>;
}
}

View File

@ -0,0 +1,24 @@
---
title: DictionarySelect
subtitle: 描述列表
---
次组件跟使用 Antd extends Select使用方法跟 Select 一样
## API
### DescriptionList
| 参数 | 说明 | 类型 | 默认值 |
|----------|------------------------------------------|-------------|-------|
| list | 数据列表 | DictionObject[] | [] |
### DictionObject
| 参数 | 说明 | 类型 | 默认值 |
|----------|------------------------------------------|-------------|-------|
| text | 显示的文字 | string | - |
| value | 选择后的值 | string number boolean | - |

View File

@ -0,0 +1,40 @@
import { queryKey, queryText } from '../../services/dictionary';
export default {
namespace: 'dictionarySelect',
state: {
list: [],
text: '',
},
effects: {
*query({ payload }, { call, put }) {
const response = yield call(queryKey, payload);
yield put({
type: 'querySuccess',
payload: {
list: response.list,
},
});
},
*queryText({ payload }, { call, put }) {
const response = yield call(queryText, payload);
yield put({
type: 'querySuccess',
payload: {
text: response.text,
},
});
},
},
reducers: {
querySuccess(state, { payload }) {
return {
...state,
...payload,
};
},
},
};

View File

@ -87,6 +87,7 @@ class RoleList extends PureComponent {
};
handleAdd = ({ fields, modalType, initValues }) => {
console.log('add ->>>', fields);
const { dispatch, data } = this.props;
const queryParams = {
pageNo: data.pageNo,

View File

@ -0,0 +1,26 @@
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import DictionarySelect from '../../components/Dictionary/DictionarySelect';
@connect(({ dictionarySelect, loading }) => ({
data: dictionarySelect,
loading: loading.models.dictionarySelect,
}))
class DictionaryValueSelect extends PureComponent {
componentDidMount() {
const { dataKey, dispatch } = this.props;
dispatch({
type: 'dictionarySelect/query',
payload: {
dataKey,
},
});
}
render() {
const { data } = this.props;
return <DictionarySelect {...this.props} list={data.list} />;
}
}
export default DictionaryValueSelect;

View File

@ -0,0 +1,26 @@
import React, { PureComponent } from 'react';
import { connect } from 'dva';
@connect(({ dictionarySelect, loading }) => ({
data: dictionarySelect,
loading: loading.models.dictionarySelect,
}))
class DictionaryValueText extends PureComponent {
componentDidMount() {
const { dataKey, dispatch } = this.props;
dispatch({
type: 'dictionarySelect/queryText',
payload: {
dataKey,
value: 1,
},
});
}
render() {
const { data } = this.props;
return <span>{data.text}</span>;
}
}
export default DictionaryValueText;

View File

@ -2,6 +2,8 @@ import React, { Component } from 'react';
import { Button } from 'antd';
import AuthorityControl from '../../components/AuthorityControl';
import UrlsContext from '../../layouts/UrlsContext';
import DictionaryValueSelect from '../Dictionary/DictionaryValueSelect';
import DictionaryValueText from '../Dictionary/DictionaryValueText';
export default class Home extends Component {
state = {};
@ -22,6 +24,9 @@ export default class Home extends Component {
<Button type="primary">按钮 控制</Button>
</AuthorityControl>
<h1>home...</h1>
<DictionaryValueSelect dataKey="gender" defaultValue={1} />
<DictionaryValueText dataKey="gender" value="1" />
</UrlsContext.Provider>
);
}

View File

@ -0,0 +1,14 @@
import { stringify } from '@/utils/request.qs';
import request from '@/utils/request';
export async function queryKey(params) {
return request(`/admin-api/admins/dictionary/getList?${stringify(params)}`, {
method: 'GET',
});
}
export async function queryText(params) {
return request(`/admin-api/admins/dictionary/queryText?${stringify(params)}`, {
method: 'GET',
});
}

View File

@ -0,0 +1,8 @@
##################### 业务模块 #####################
## MobileCodeService
modules.mobile-code-service.code-expire-time-millis = 600000
modules.mobile-code-service.send-maximum-quantity-per-day = 10
modules.mobile-code-service.send-frequency = 60000
## OAuth2CodeService
modules.oauth2-code-service.access-token-expire-time-millis = 2880000
modules.oauth2-code-service.refresh-token-expire-time-millis = 43200000

View File

@ -0,0 +1,32 @@
spring:
# datasource
datasource:
url: jdbc:mysql://127.0.0.1:33061/mall_user?useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
# server
server:
port: 8082
# mybatis
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: cn.iocoder.mall.user.dataobject
# dubbo
dubbo:
application:
name: user-service
registry:
address: zookeeper://127.0.0.1:2181
protocol:
port: -1
name: dubbo
scan:
base-packages: cn.iocoder.mall.user.service
demo:
service:
version: 1.0.0

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.dao.MobileCodeMapper">
<insert id="insert" parameterType="MobileCodeDO">
INSERT INTO mobile_code (
id, mobile, code, today_index, used,
used_uid, used_time, create_time
) VALUES (
#{id}, #{mobile}, #{code}, #{todayIndex}, #{used},
#{usedUid}, #{usedTime}, #{createTime}
)
</insert>
<update id="update" parameterType="MobileCodeDO">
UPDATE mobile_code
<set>
<if test="used != null"> used = #{used}, </if>
<if test="usedUid != null"> used_uid = #{usedUid}, </if>
<if test="usedTime != null"> used_time = #{usedTime}, </if>
</set>
WHERE id = #{id}
</update>
<select id="selectLast1ByMobile" parameterType="String" resultType="MobileCodeDO">
SELECT
id, mobile, code, today_index, used,
used_uid, used_time, create_time
FROM mobile_code
WHERE mobile = #{mobile}
ORDER BY id DESC
LIMIT 1
</select>
</mapper>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.dao.OAuth2AccessTokenMapper">
<insert id="insert" parameterType="OAuth2AccessTokenDO">
INSERT INTO oauth2_access_token (
id, refresh_token, adminId, valid, expires_time,
create_time
) VALUES (
#{id}, #{refreshToken}, #{adminId}, #{valid}, #{expiresTime},
#{createTime}
)
</insert>
<select id="selectByTokenId" parameterType="String" resultType="OAuth2AccessTokenDO">
SELECT
id, adminId, valid, expires_time
FROM oauth2_access_token
WHERE id = #{id}
</select>
</mapper>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.dao.OAuth2RefreshTokenMapper">
<insert id="insert" parameterType="OAuth2RefreshTokenDO">
INSERT INTO oauth2_refresh_token (
id, adminId, valid, expires_time, create_time
) VALUES (
#{id}, #{adminId}, #{valid}, #{expiresTime}, #{createTime}
)
</insert>
</mapper>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.dao.UserMapper">
<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO users (
id, mobile, create_time
) VALUES (
#{id}, #{mobile}, #{createTime}
)
</insert>
<select id="selectByMobile" parameterType="String" resultType="UserDO">
SELECT
id, mobile
FROM users
WHERE mobile = #{mobile}
</select>
</mapper>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.dao.UserRegisterMapper">
<insert id="insert" parameterType="UserRegisterDO">
INSERT INTO user_register (
id, create_time
) VALUES (
#{id}, #{createTime}
)
</insert>
</mapper>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
<typeAlias alias="Long" type="java.lang.Long"/>
<typeAlias alias="HashMap" type="java.util.HashMap"/>
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
</typeAliases>
</configuration>

View File

@ -0,0 +1,41 @@
package cn.iocoder.mall.user.convert;
import cn.iocoder.mall.user.dataobject.OAuth2AccessTokenDO;
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
import cn.iocoder.mall.user.service.api.bo.OAuth2AuthenticationBO;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2019-03-05T10:35:05+0800",
comments = "version: 1.3.0.Final, compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)"
)
public class OAuth2ConvertImpl implements OAuth2Convert {
@Override
public OAuth2AccessTokenBO convertToAccessToken(OAuth2AccessTokenDO oauth2AccessTokenDO) {
if ( oauth2AccessTokenDO == null ) {
return null;
}
OAuth2AccessTokenBO oAuth2AccessTokenBO = new OAuth2AccessTokenBO();
oAuth2AccessTokenBO.setAccessToken( oauth2AccessTokenDO.getId() );
oAuth2AccessTokenBO.setRefreshToken( oauth2AccessTokenDO.getRefreshToken() );
return oAuth2AccessTokenBO;
}
@Override
public OAuth2AuthenticationBO convertToAuthentication(OAuth2AccessTokenDO oauth2AccessTokenDO) {
if ( oauth2AccessTokenDO == null ) {
return null;
}
OAuth2AuthenticationBO oAuth2AuthenticationBO = new OAuth2AuthenticationBO();
oAuth2AuthenticationBO.setUid( oauth2AccessTokenDO.getUid() );
return oAuth2AuthenticationBO;
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.user.convert;
import cn.iocoder.mall.user.dataobject.UserDO;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2019-03-05T10:35:05+0800",
comments = "version: 1.3.0.Final, compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)"
)
public class UserConvertImpl implements UserConvert {
@Override
public UserBO convert(UserDO userDO) {
if ( userDO == null ) {
return null;
}
UserBO userBO = new UserBO();
userBO.setMobile( userDO.getMobile() );
return userBO;
}
}