Merge pull request #322 from 2betop/master

见提交 commits
This commit is contained in:
liaoxuezhi 2019-11-01 16:52:55 +08:00 committed by GitHub
commit 0d13b72185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 173 additions and 135 deletions

View File

@ -6,7 +6,7 @@ module.exports = function(req, res) {
if (pathname === 'sample' && (req.method === 'POST' || req.method === 'PUT')) {
return store(req, res);
} else if (/sample\/(\d+(?:,\d+)*)?$/.test(pathname)) {
if ((req.method === 'POST' || req.method === 'PUT')) {
if (req.method === 'POST' || req.method === 'PUT') {
return update(req, res, RegExp.$1);
} else if (req.method === 'DELETE') {
return del(req, res, RegExp.$1);
@ -18,8 +18,7 @@ module.exports = function(req, res) {
}
return index(req, res);
}
};
function index(req, res) {
const perPage = parseInt(req.query.perPage, 10);
@ -43,7 +42,7 @@ function index(req, res) {
if (req.query.orderBy) {
const field = req.query.orderBy;
const direction = req.query.orderDir === 'desc' ? -1 : 1;
items = items.sort(function (a, b) {
items = items.sort(function(a, b) {
a = String(a[field]);
b = String(b[field]);
@ -57,20 +56,27 @@ function index(req, res) {
});
}
return res.json({
let response = () =>
res.json({
status: 0,
msg: 'ok',
data: {
count: items.length,
rows: perPage ? items.splice((page -1) * perPage, perPage) : items.concat()
rows: perPage ? items.splice((page - 1) * perPage, perPage) : items.concat()
}
});
if (req.query.waitSeconds) {
return setTimeout(response, parseInt(req.query.waitSeconds, 10) * 1000);
}
return response();
}
function store(req, res) {
const data = Object.assign({}, req.body);
data.id = DB.length ? (DB[DB.length - 1].id + 1) : 1;
data.id = DB.length ? DB[DB.length - 1].id + 1 : 1;
DB.push(data);
@ -83,8 +89,9 @@ function store(req, res) {
function update(req, res, id) {
const ids = id.split(',');
if (!ids.every(function(id) {
const idx = DB.findIndex(function (item) {
if (
!ids.every(function(id) {
const idx = DB.findIndex(function(item) {
return item.id == id;
});
@ -96,7 +103,8 @@ function update(req, res, id) {
item.id = id;
DB.splice(idx, 1, item);
return true;
})) {
})
) {
return res.json({
status: 404,
msg: '保存失败,数据可能已被删除!'
@ -113,8 +121,9 @@ function del(req, res, id) {
const ids = id.split(',');
console.log(ids);
if (!ids.every(function(id) {
const idx = DB.findIndex(function (item) {
if (
!ids.every(function(id) {
const idx = DB.findIndex(function(item) {
return item.id == id;
});
@ -124,7 +133,8 @@ function del(req, res, id) {
DB.splice(idx, 1);
return true;
})) {
})
) {
return res.json({
status: 404,
msg: '保存失败,数据可能已被删除!'
@ -140,8 +150,10 @@ function del(req, res, id) {
function bulkUpdate(req, res) {
const rowDiff = req.body.rowsDiff;
const ids = req.body.ids ? req.body.ids.split(',') : [];
if (!ids.length || !ids.every(function(id, index) {
const idx = DB.findIndex(function (item) {
if (
!ids.length ||
!ids.every(function(id, index) {
const idx = DB.findIndex(function(item) {
return item.id == id;
});
@ -153,7 +165,8 @@ function bulkUpdate(req, res) {
item.id = id;
DB.splice(idx, 1, item);
return true;
})) {
})
) {
return res.json({
status: 404,
msg: '保存失败,数据可能已被删除!'
@ -172,8 +185,10 @@ function bulkUpdate2(req, res) {
delete data.ids;
const ids = req.body.ids ? req.body.ids.split(',') : [];
if (!ids.length || !ids.every(function(id, index) {
const idx = DB.findIndex(function (item) {
if (
!ids.length ||
!ids.every(function(id, index) {
const idx = DB.findIndex(function(item) {
return item.id == id;
});
@ -185,7 +200,8 @@ function bulkUpdate2(req, res) {
item.id = id;
DB.splice(idx, 1, item);
return true;
})) {
})
) {
return res.json({
status: 404,
msg: '保存失败,数据可能已被删除!'

View File

@ -15,7 +15,7 @@
&-actions {
display: inline-block;
> * {
>* {
margin-right: $Crud-toolbar-gap;
}
}
@ -23,14 +23,14 @@
&-header {
padding: $List-toolbar-paddingY $List-toolbar-paddingX;
> * + .#{$ns}Button,
> * + .#{$ns}ButtonGroup,
> * + .#{$ns}ButtonToolbar {
>*+.#{$ns}Button,
>*+.#{$ns}ButtonGroup,
>*+.#{$ns}ButtonToolbar {
margin-left: $Crud-toolbar-gap;
}
}
&-header + &-toolbar {
&-header+&-toolbar {
padding-top: 0;
}
@ -85,7 +85,7 @@
.#{$ns}ListItem {
@include clearfix();
& + & {
&+& {
border-top: $ListItem-borderWidth solid $ListItem-borderColor;
}
@ -134,6 +134,7 @@
position: relative;
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
&-fieldLabel {
@ -146,7 +147,7 @@
border-color: $ListItem-onChecked-borderColor;
color: $ListItem-onChecked-color;
+ .#{$ns}ListItem {
+.#{$ns}ListItem {
border-color: $ListItem-onChecked-borderColor;
}
@ -161,7 +162,7 @@
border-color: $ListItem-onModified-borderColor;
color: $ListItem-onModified-color;
+ .#{$ns}ListItem {
+.#{$ns}ListItem {
border-color: $ListItem-onModified-borderColor;
}

View File

@ -24,6 +24,11 @@
border: $borderWidth solid $borderColor;
border-radius: $borderRadius;
&>* {
position: relative;
z-index: 2;
}
&-overlay {
position: fixed !important;
top: 0;
@ -32,10 +37,5 @@
z-index: 1;
bottom: 0;
background: transparent;
& + * {
position: relative;
z-index: 2;
}
}
}

View File

@ -33,7 +33,7 @@
&.is-disabled {
background: $gray200;
> &-input {
>&-input {
color: $text--muted-color;
}
}
@ -78,7 +78,7 @@
}
}
.#{$ns}DateControl:not(.is-inline) > .#{$ns}DatePicker {
.#{$ns}DateControl:not(.is-inline)>.#{$ns}DatePicker {
display: flex;
}
@ -107,6 +107,7 @@
.rdtPicker {
margin-top: 0;
padding: $gap-md;
background: transparent;
border: none;
.dow {
@ -233,8 +234,7 @@
font-size: $fontSizeSm;
}
@include button-variant(
$Calendar-btn-bg,
@include button-variant($Calendar-btn-bg,
$Calendar-btn-border,
$Calendar-btn-color,
$Calendar-btn-onHover-bg,
@ -242,18 +242,16 @@
$Calendar-btn-onHover-color,
$Calendar-btn-onActive-bg,
$Calendar-btn-onActive-border,
$Calendar-btn-onActive-color
);
$Calendar-btn-onActive-color);
border-radius: $Calendar-btn-borderRadius;
& + .rdtBtn {
&+.rdtBtn {
margin-left: $gap-xs;
}
&Cancel {
@include button-variant(
$Calendar-btnCancel-bg,
@include button-variant($Calendar-btnCancel-bg,
$Calendar-btnCancel-border,
$Calendar-btnCancel-color,
$Calendar-btnCancel-onHover-bg,
@ -261,8 +259,7 @@
$Calendar-btnCancel-onHover-color,
$Calendar-btnCancel-onActive-bg,
$Calendar-btnCancel-onActive-border,
$Calendar-btnCancel-onActive-color
);
$Calendar-btnCancel-onActive-color);
}
}

View File

@ -40,16 +40,23 @@
}
&-pasteTip {
display: block;
pointer-events: none;
left: 0;
top: 50%;
transform: translateY(-50%);
position: absolute;
color: $text--muted-color;
font-size: 12px;
transform: scale(0.8);
transform-origin: 100% 100%;
right: 0;
bottom: 0;
padding: 2px 5px;
background: rgba(255, 255, 255, 0.8);
font-size: $Tooltip--attr-fontSize;
line-height: $Tooltip--attr-lineHeigt;
text-align: left;
white-space: nowrap;
background: $Tooltip--attr-bg;
border: $Tooltip--attr-borderWidth solid $Tooltip--attr-borderColor;
border-radius: $Tooltip--attr-borderRadius;
box-shadow: $Tooltip--attr-boxShadow;
left: 100%;
color: $Tooltip--attr-color;
padding: $Tooltip--attr-paddingY $Tooltip--attr-paddingX;
margin: 30px 0 0 $Tooltip--attr-gap;
}
&-dropzone:focus &-addBtn {

View File

@ -17,10 +17,8 @@
&-addOn {
background: $InputGroup-addOn-bg;
border: $InputGroup-addOn-borderWidth solid
$InputGroup-addOn-borderColor;
line-height: $InputGroup-height - $InputGroup-paddingY * 2 -
$InputGroup-addOn-borderWidth * 2;
border: $InputGroup-addOn-borderWidth solid $InputGroup-addOn-borderColor;
line-height: $InputGroup-height - $InputGroup-paddingY * 2 - $InputGroup-addOn-borderWidth * 2;
height: $InputGroup-height;
box-sizing: border-box;
padding: $InputGroup-paddingY $InputGroup-paddingX;
@ -47,8 +45,7 @@
&-btn {
.#{$ns}Button {
border-radius: 0;
border: $InputGroup-button-borderWidth solid
$InputGroup-button-borderColor;
border: $InputGroup-button-borderWidth solid $InputGroup-button-borderColor;
}
&:not(:last-child) .#{$ns}Button {
@ -73,6 +70,7 @@
.#{$ns}TextControl-input {
flex-basis: 0;
flex-grow: 1;
display: inline-flex;
&:not(:first-child) {
border-top-left-radius: 0;
@ -90,9 +88,7 @@
@if $InputGroup-select-borderWidth {
.#{$ns}Select {
background-color: $InputGroup-select-bg;
border: $InputGroup-select-borderWidth
solid
$InputGroup-select-borderColor;
border: $InputGroup-select-borderWidth solid $InputGroup-select-borderColor;
@if $InputGroup-select-color !=$Form-select-color {
color: $InputGroup-select-color;
@ -137,6 +133,7 @@
}
&.is-focused {
.#{$ns}InputGroup-addOn,
.#{$ns}TextControl-input,
.#{$ns}Select,
@ -156,9 +153,7 @@
}
}
@if $InputGroup-select-onFocused-arrowColor
!=$Form-select-caret-iconColor
{
@if $InputGroup-select-onFocused-arrowColor !=$Form-select-caret-iconColor {
.#{$ns}Select-arrow {
color: $InputGroup-select-onFocused-arrowColor;
}

View File

@ -600,7 +600,7 @@ export function HocStoreFactory(renderer: {storeType: string; extendsData?: bool
path: this.props.$path,
storeType: renderer.storeType,
parentId: this.props.store ? this.props.store.id : ''
}));
} as any));
if (renderer.extendsData === false) {
store.initData(
@ -656,7 +656,8 @@ export function HocStoreFactory(renderer: {storeType: string; extendsData?: bool
store.data,
nextProps.store.data,
props.scope,
nextProps.dataUpdatedAt !== props.dataUpdatedAt
nextProps.dataUpdatedAt !== props.dataUpdatedAt,
store
)
);
@ -680,7 +681,7 @@ export function HocStoreFactory(renderer: {storeType: string; extendsData?: bool
...store.data
})
);
} else if (nextProps.scope !== props.scope) {
} else if (isObjectShallowModified(props.scope, nextProps.scope)) {
store.initData(
createObject(nextProps.scope, {
...nextProps.data,

View File

@ -938,14 +938,14 @@ export default class ImageControl extends React.Component<ImageProps, ImageState
data-position="right"
>
<Icon icon="plus" className="icon" />
</label>
) : null}
{isFocused ? (
<span className={cx('ImageControl-pasteTip')}>
</span>
) : null}
</label>
) : null}
{!autoUpload && !hideUploadButton && files.length ? (
<Button

View File

@ -7,6 +7,8 @@ import {Schema, PlainObject, FunctionPropertyNames} from '../types';
import {evalExpression} from './tpl';
import {boundMethod} from 'autobind-decorator';
import qs from 'qs';
import {IIRendererStore} from '../store';
import {IFormStore} from '../store/form';
// 方便取值的时候能够把上层的取到,但是获取的时候不会全部把所有的数据获取到。
export function createObject(
@ -53,13 +55,27 @@ export function extendObject(to: any, from?: any) {
return obj;
}
export function syncDataFromSuper(data: any, superObject: any, prevSuperObject: any, force?: boolean) {
export function syncDataFromSuper(
data: any,
superObject: any,
prevSuperObject: any,
force?: boolean,
store?: IIRendererStore
) {
const obj = {
...data
};
let keys = Object.keys(obj);
// 如果是 form store则从父级同步 formItem 种东西。
if (store && store.storeType === 'FormStore') {
keys = uniq((store as IFormStore).items.map(item => item.name));
force = false;
}
if (superObject || prevSuperObject) {
Object.keys(obj).forEach(key => {
keys.forEach(key => {
if (
((superObject && typeof superObject[key] !== 'undefined') ||
(prevSuperObject && typeof prevSuperObject[key] !== 'undefined')) &&
@ -432,7 +448,7 @@ export function difference<T extends {[propName: string]: any}, U extends {[prop
// todo 数组要不要深入分析?我看先别了。
result[key] = a;
} else if (lodashIsObject(a) && lodashIsObject(b)) {
result[key] = changes(a, b);
result[key] = changes(a as any, b as any);
} else {
result[key] = a;
}
@ -517,7 +533,7 @@ export function until(
getCanceler: (fn: () => any) => void,
interval: number = 5000
) {
let timer: number;
let timer: NodeJS.Timeout;
let stoped: boolean = false;
return new Promise((resolve, reject) => {

View File

@ -2,7 +2,7 @@ import {reigsterTplEnginer, filter} from './tpl';
import moment from 'moment';
import {PlainObject} from '../types';
import isPlainObject = require('lodash/isPlainObject');
import {createObject, isObject, setVariable} from './helper';
import {createObject, isObject, setVariable, qsstringify} from './helper';
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
@ -387,9 +387,14 @@ export const tokenize = (str: string, data: object, defaultFilter: string = '| h
return str;
}
return str.replace(/(\\)?\$(?:([a-z0-9_\.]+|&)|{([^}{]+?)})/gi, (_, escape) =>
return str
.replace(/(\\)?\$(?:([a-z0-9_\.]+|&)|{([^}{]+?)})/gi, (_, escape) =>
escape ? _.substring(1) : resolveVariableAndFilter(_, data, defaultFilter)
);
)
.replace(/\$\$/g, (_, index: number, source: string) => {
const prefix = source[index - 1];
return prefix === '=' ? encodeURIComponent(JSON.stringify(data)) : qsstringify(data);
});
};
function resolveMapping(value: any, data: PlainObject) {