Skip to content

Commit 5bdccc4

Browse files
committed
[layui]adjust
1 parent 0272cc0 commit 5bdccc4

File tree

9 files changed

+259
-9
lines changed

9 files changed

+259
-9
lines changed

_antd/table/row-click.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { Table } from 'antd';
2+
3+
// In the fifth row, other columns are merged into first column
4+
// by setting it's colSpan to be 0
5+
const renderContent = (value, row, index) => {
6+
const obj = {
7+
children: value,
8+
props: {},
9+
};
10+
if (index === 4) {
11+
obj.props.colSpan = 0;
12+
}
13+
return obj;
14+
};
15+
16+
const columns = [
17+
{
18+
title: 'Name',
19+
dataIndex: 'name',
20+
render: (text, row, index) => {
21+
if (index < 4) {
22+
return <a>{text}</a>;
23+
}
24+
return {
25+
children: <a>{text}</a>,
26+
props: {
27+
colSpan: 5,
28+
},
29+
};
30+
},
31+
},
32+
{
33+
title: 'Age',
34+
dataIndex: 'age',
35+
render: renderContent,
36+
},
37+
{
38+
title: 'Home phone',
39+
colSpan: 2,
40+
dataIndex: 'tel',
41+
render: (value, row, index) => {
42+
const obj = {
43+
children: value,
44+
props: {},
45+
};
46+
if (index === 2) {
47+
obj.props.rowSpan = 2;
48+
}
49+
// These two are merged into above cell
50+
if (index === 3) {
51+
obj.props.rowSpan = 0;
52+
}
53+
if (index === 4) {
54+
obj.props.colSpan = 0;
55+
}
56+
return obj;
57+
},
58+
},
59+
{
60+
title: 'Phone',
61+
colSpan: 0,
62+
dataIndex: 'phone',
63+
render: renderContent,
64+
},
65+
{
66+
title: 'Address',
67+
dataIndex: 'address',
68+
render: renderContent,
69+
},
70+
];
71+
72+
const data = [
73+
{
74+
key: '1',
75+
name: 'John Brown',
76+
age: 32,
77+
tel: '0571-22098909',
78+
phone: 18889898989,
79+
address: 'New York No. 1 Lake Park',
80+
},
81+
{
82+
key: '2',
83+
name: 'Jim Green',
84+
tel: '0571-22098333',
85+
phone: 18889898888,
86+
age: 42,
87+
address: 'London No. 1 Lake Park',
88+
},
89+
{
90+
key: '3',
91+
name: 'Joe Black',
92+
age: 32,
93+
tel: '0575-22098909',
94+
phone: 18900010002,
95+
address: 'Sidney No. 1 Lake Park',
96+
},
97+
{
98+
key: '4',
99+
name: 'Jim Red',
100+
age: 18,
101+
tel: '0575-22098909',
102+
phone: 18900010002,
103+
address: 'London No. 2 Lake Park',
104+
},
105+
{
106+
key: '5',
107+
name: 'Jake White',
108+
age: 18,
109+
tel: '0575-22098909',
110+
phone: 18900010002,
111+
address: 'Dublin No. 2 Lake Park',
112+
},
113+
];
114+
function App() {
115+
return (
116+
<div>
117+
<Table columns={columns} dataSource={data} bordered />
118+
</div>
119+
);
120+
}
121+
122+
ReactDOM.render(<App />, mountNode);
123+

_fetch/umi-request/demo.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import react, { useEffect } from "react"
2+
import ReactDOM from "react-dom"
3+
import axios from 'axios'
4+
import request from 'umi-request'
5+
6+
function App() {
7+
8+
useEffect(() => {
9+
// request.get("/mock/data-strange.json").then((res) => {
10+
// debugger
11+
// })
12+
13+
// @TODO chrome-v.80 会报错 --> 网页奔溃 !!!
14+
// axios.get("/mock/data-strange.json").then((res) => {
15+
// debugger
16+
// })
17+
18+
$.ajax({
19+
url: '/mock/data-crash.json',
20+
method: 'GET',
21+
success: (res) => {
22+
console.log(res)
23+
JSON.parse(res)
24+
25+
debugger
26+
}
27+
})
28+
29+
});
30+
31+
32+
return (
33+
<div>
34+
发送请求
35+
</div>
36+
);
37+
}
38+
39+
ReactDOM.render(<App />, mountNode);
40+

_misc/layui/treeTable.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
<script src="/plugins/layui/layui.js"></script>
2121
<!--<script src="https://www.layuicdn.com/layui-v2.5.4/layui.js"></script>-->
2222

23+
2324
</body>
2425
</html>

_misc/layui/treeTable.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useEffect} from "react"
22
import ReactDOM from "react-dom"
33

4-
const data = [
4+
var data = [
55
{
66
"id": "1",
77
"name": "xxx",
@@ -156,7 +156,7 @@ const data = [
156156

157157

158158

159-
const initTree = () => {
159+
var initTree = () => {
160160
layui.config({
161161
base: '/plugins/', // 模块所在目录
162162
version: 'v1.5.2' // 插件版本号
@@ -224,11 +224,11 @@ const initTree = () => {
224224

225225
treeTable.on('row(myTable)', (obj) => {
226226

227-
const flag = 'DATA_HAS_APPEND_TABLE'
227+
var flag = 'DATA_HAS_APPEND_TABLE'
228228
var $tr = obj.tr
229229

230230
// 判断当前行是否有可供展开的数据
231-
const info = $tr.data() || {}
231+
var info = $tr.data() || {}
232232
if (obj.data && !obj.data.children && info.indent != null) {
233233

234234
$tr.toggleClass('ew-tree-table-open')
@@ -241,7 +241,7 @@ const initTree = () => {
241241
// 标记该行已经追加过表格
242242
$tr.attr(flag, true)
243243

244-
const indent = (info.indent + 1) * 21 + 14
244+
var indent = (info.indent + 1) * 21 + 14
245245
console.log(obj)
246246
// // 得到当前行元素对象
247247
// console.log(obj.tr)
@@ -309,7 +309,7 @@ const initTree = () => {
309309
// @fix 允许行冒泡, 修复图标文字的点击问题
310310
// ew-tree-table-td-single
311311
$('[lay-filter="myTable"]').find('.ew-tree-tips,.ew-tree-table-td-single,.ew-tree-pack').click(function () {
312-
const $tr = $(this).parents('tr')
312+
var $tr = $(this).parents('tr')
313313
$tr.click()
314314
})
315315

config/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
// 默认模板位置
33
template: './template/template-cdn-antd.ejs',
4+
// template: './template/template.ejs',
45

56
// 默认meta位置
67
meta: "./template/template.json",
@@ -44,7 +45,7 @@ export default {
4445
// entry: './_antd/form/*.js',
4546
// entry: './_antd/table/*.js',
4647
// entry: './_antd/doddle/*.js',
47-
// entry: './_antd/table/editable/*.js',
48+
// entry: './_antd/table/**/*.js',
4849
// entry: './_antd/tree/*.js',
4950

5051

@@ -74,14 +75,15 @@ export default {
7475
// entry: './_rsuite/table/*.js',
7576

7677
// 杂项
77-
entry: './_misc/**/*.js',
78+
// entry: './_misc/**/*.js',
7879

7980

8081
// eui
8182
// entry: './_eui/*.js',
8283

8384
// fetch请求
8485
// entry: './_fetch/reqwest/*.js',
86+
entry: './_fetch/umi-request/*.js',
8587
// entry: './_fetch/axios/*.js',
8688
// entry: './_fetch/swr/*.js',
8789

@@ -108,5 +110,4 @@ export default {
108110
// Ecma-代码测试
109111
// entry: './_ecma/**/browser-*.js',
110112
// entry: './_ecma/async/**/browser-*.js',
111-
112113
}

public/mock/data-crash.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"a": 2.1,
4+
"b": 1,
5+
"c": "hello"
6+
},
7+
{
8+
"a": null,
9+
"b": 2,
10+
"c": {
11+
"a": 2.1,
12+
"b": 1.1,
13+
"c": "hello"
14+
}
15+
}
16+
]

public/mock/data-strange.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
3+
"data": [
4+
{
5+
"id": null,
6+
"cost": null,
7+
"unitPrice": 1077.977,
8+
"costRatio": 12,
9+
"children": [
10+
{
11+
"children": []
12+
}
13+
]
14+
},
15+
{
16+
"id": null,
17+
"cost": null,
18+
"unitPrice": null,
19+
"costRatio": 0,
20+
"children": [
21+
{
22+
"id": null,
23+
"cost": 10,
24+
"unitPrice": 249.2,
25+
"costRatio": 23.1,
26+
"children": null
27+
}
28+
]
29+
}
30+
]
31+
}

public/mock/data-strange.str

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"data": [
3+
{
4+
"id": null,
5+
"cost": null,
6+
"unitPrice": 1077.977,
7+
"costRatio": 12,
8+
"children": [
9+
{
10+
"children": []
11+
}
12+
]
13+
},
14+
{
15+
"id": null,
16+
"cost": null,
17+
"unitPrice": null,
18+
"costRatio": null,
19+
"children": [
20+
{
21+
"id": null,
22+
"cost": 10,
23+
"unitPrice": 249.2,
24+
"costRatio": 23.1,
25+
"children": null
26+
}
27+
]
28+
}
29+
]
30+
}

template/template.ejs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<link rel="icon" href="/favicon.png" type="image/x-icon" />
88
<title><%= htmlWebpackPlugin.options.title %></title>
9+
910
<link href="https://cdn.bootcss.com/normalize/7.0.0/normalize.min.css" rel="stylesheet">
1011
<link href="https://cdn.bootcss.com/tailwindcss/0.7.3/utilities.min.css" rel="stylesheet">
1112
<link href="https://cdn.bootcss.com/antd/3.23.6/antd.min.css" rel="stylesheet">
@@ -14,5 +15,12 @@
1415
<body>
1516

1617
<div id="root" class="p-5"></div>
18+
19+
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
20+
<script>
21+
// 用于挂载
22+
var mountNode = document.getElementById('root')
23+
</script>
24+
1725
</body>
1826
</html>

0 commit comments

Comments
 (0)