Skip to content

Commit e714d7a

Browse files
author
tangweikun
committed
✨ Add Sample-4
1 parent 2ad3695 commit e714d7a

File tree

6 files changed

+183
-34
lines changed

6 files changed

+183
-34
lines changed
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
// HELP:
22

3-
var order500 = function(orderType, pay, stock) {
3+
var order500 = function (orderType, pay, stock) {
44
if (orderType === 1 && pay === true) {
5-
console.log('500元定金预购,得到100优惠券')
5+
console.log("500元定金预购,得到100优惠券");
66
} else {
7-
return 'nextSuccessor' // 我不知道下一个节点是谁,反正把请求往后面传递
7+
return "nextSuccessor"; // 我不知道下一个节点是谁,反正把请求往后面传递
88
}
9-
}
9+
};
1010

11-
var order200 = function(orderType, pay, stock) {
11+
var order200 = function (orderType, pay, stock) {
1212
if (orderType === 2 && pay === true) {
13-
console.log('200元定金预购,得到50优惠券')
13+
console.log("200元定金预购,得到50优惠券");
1414
} else {
15-
return 'nextSuccessor' // 我不知道下一个节点是谁,反正把请求往后面传递
15+
return "nextSuccessor"; // 我不知道下一个节点是谁,反正把请求往后面传递
1616
}
17-
}
17+
};
1818

19-
var orderNormal = function(orderType, pay, stock) {
20-
if (stock > 0) console.log('普通购买,无优惠券')
21-
else console.log('手机库存不足')
22-
}
19+
var orderNormal = function (orderType, pay, stock) {
20+
if (stock > 0) console.log("普通购买,无优惠券");
21+
else console.log("手机库存不足");
22+
};
2323

24-
var Chain = function(fn) {
25-
this.fn = fn
26-
this.successor = null
27-
}
28-
Chain.prototype.setNextSuccessor = function(successor) {
29-
return (this.successor = successor)
30-
}
31-
Chain.prototype.passRequest = function() {
32-
var ret = this.fn.apply(this, arguments)
33-
if (ret === 'nextSuccessor') {
24+
var Chain = function (fn) {
25+
this.fn = fn;
26+
this.successor = null;
27+
};
28+
Chain.prototype.setNextSuccessor = function (successor) {
29+
return (this.successor = successor);
30+
};
31+
Chain.prototype.passRequest = function () {
32+
var ret = this.fn.apply(this, arguments);
33+
if (ret === "nextSuccessor") {
3434
return (
3535
this.successor &&
3636
this.successor.passRequest.apply(this.successor, arguments)
37-
)
37+
);
3838
}
39-
return ret
40-
}
39+
return ret;
40+
};
4141

42-
var chainOrder500 = new Chain(order500)
43-
var chainOrder200 = new Chain(order200)
44-
var chainOrderNormal = new Chain(orderNormal)
42+
var chainOrder500 = new Chain(order500);
43+
var chainOrder200 = new Chain(order200);
44+
var chainOrderNormal = new Chain(orderNormal);
4545

46-
chainOrder500.setNextSuccessor(chainOrder200)
47-
chainOrder200.setNextSuccessor(chainOrderNormal)
46+
chainOrder500.setNextSuccessor(chainOrder200);
47+
chainOrder200.setNextSuccessor(chainOrderNormal);
4848

49-
chainOrder500.passRequest(1, true, 500) // 输出:500元定金预购,得到100优惠券
50-
chainOrder500.passRequest(2, true, 500) //输出:200元定金预购,得到50优惠券
51-
chainOrder500.passRequest(3, true, 500) //输出:普通购买,无优惠券
52-
chainOrder500.passRequest(1, false, 0) //输出:手机库存不足
49+
chainOrder500.passRequest(1, true, 500); // 输出:500元定金预购,得到100优惠券
50+
chainOrder500.passRequest(2, true, 500); //输出:200元定金预购,得到50优惠券
51+
chainOrder500.passRequest(3, true, 500); //输出:普通购买,无优惠券
52+
chainOrder500.passRequest(1, false, 0); //输出:手机库存不足
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function leaveRequest(days) {
2+
return handleByDirector(days);
3+
}
4+
5+
// 主管处理该请假申请
6+
function handleByDirector() {
7+
const result = Math.random() > 0.5 ? "reject" : "accept";
8+
if (result === "reject") {
9+
return result;
10+
}
11+
if (days < 3) {
12+
return "accept";
13+
}
14+
return handleByManager();
15+
}
16+
17+
// 经理处理该请假申请
18+
function handleByManager() {
19+
const result = Math.random() > 0.5 ? "reject" : "accept";
20+
if (result === "reject") {
21+
return result;
22+
}
23+
if (days < 5) {
24+
return "accept";
25+
}
26+
return handleByTopManager();
27+
}
28+
29+
// 总经理处理该请假申请
30+
function handleByTopManager() {
31+
const result = Math.random() > 0.5 ? "reject" : "accept";
32+
return result;
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// bad
2+
function leaveRequest(days) {
3+
const resultByDirector = handleByDirector();
4+
if (resultByDirector === "reject") {
5+
return "reject";
6+
}
7+
if (days < 3) {
8+
return "accept";
9+
}
10+
11+
const resultByManager = handleByManager();
12+
if (resultByManager === "reject") {
13+
return "reject";
14+
}
15+
if (days < 5) {
16+
return "accept";
17+
}
18+
19+
const resultByTopManager = handleByTopManager();
20+
if (resultByTopManager === "reject") {
21+
return "reject";
22+
}
23+
return "accept";
24+
}
25+
26+
// 主管处理该请假申请
27+
function handleByDirector() {
28+
return Math.random() > 0.5 ? "reject" : "accept";
29+
}
30+
31+
// 经理处理该请假申请
32+
function handleByManager() {
33+
return Math.random() > 0.5 ? "reject" : "accept";
34+
}
35+
36+
// 总经理处理该请假申请
37+
function handleByTopManager() {
38+
return Math.random() > 0.5 ? "reject" : "accept";
39+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## 员工请假
2+
3+
以请假流程为例,一般公司普通员工的请假流程简化如下:
4+
5+
普通员工发起一个请假申请,当请假天数小于 3 天时只需要得到主管批准即可;当请假天数大于 3 天时,主管批准后还需要提交给经理审批,经理审批通过,若请假天数大于 7 天还需要进一步提交给总经理审批。
6+
7+
![](./Sample-4.png)
48.1 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<mxfile host="65bd71144e">
2+
<diagram id="_nKMrMbocazPtErH9bCT" name="Page-1">
3+
<mxGraphModel dx="833" dy="617" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0"/>
6+
<mxCell id="1" parent="0"/>
7+
<mxCell id="10" value="邮箱登录" style="edgeStyle=none;html=1;" edge="1" parent="1" source="2" target="9">
8+
<mxGeometry relative="1" as="geometry"/>
9+
</mxCell>
10+
<mxCell id="14" value="手机登录" style="edgeStyle=none;html=1;" edge="1" parent="1" source="2" target="13">
11+
<mxGeometry relative="1" as="geometry"/>
12+
</mxCell>
13+
<mxCell id="2" value="登录方式" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
14+
<mxGeometry x="10" y="190" width="80" height="30" as="geometry"/>
15+
</mxCell>
16+
<mxCell id="16" value="存在为空" style="edgeStyle=none;html=1;" edge="1" parent="1" source="9" target="15">
17+
<mxGeometry relative="1" as="geometry"/>
18+
</mxCell>
19+
<mxCell id="18" value="都不为空" style="edgeStyle=none;html=1;" edge="1" parent="1" source="9" target="17">
20+
<mxGeometry relative="1" as="geometry"/>
21+
</mxCell>
22+
<mxCell id="9" value="检查邮箱、密码是否为空" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
23+
<mxGeometry x="171.25" y="95" width="95" height="40" as="geometry"/>
24+
</mxCell>
25+
<mxCell id="25" value="都不为空" style="edgeStyle=none;html=1;exitX=0.75;exitY=0;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="13" target="17">
26+
<mxGeometry relative="1" as="geometry"/>
27+
</mxCell>
28+
<mxCell id="26" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0.75;entryDx=0;entryDy=0;" edge="1" parent="1" source="13" target="15">
29+
<mxGeometry relative="1" as="geometry"/>
30+
</mxCell>
31+
<mxCell id="13" value="检查邮箱、密码是否为空" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
32+
<mxGeometry x="188.75" y="330" width="77.5" height="30" as="geometry"/>
33+
</mxCell>
34+
<mxCell id="15" value="失败" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
35+
<mxGeometry x="480" y="30" width="80" height="30" as="geometry"/>
36+
</mxCell>
37+
<mxCell id="20" value="存在" style="edgeStyle=none;html=1;" edge="1" parent="1" source="17" target="19">
38+
<mxGeometry relative="1" as="geometry"/>
39+
</mxCell>
40+
<mxCell id="22" value="不存在" style="edgeStyle=none;html=1;exitX=1;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="17" target="15">
41+
<mxGeometry relative="1" as="geometry"/>
42+
</mxCell>
43+
<mxCell id="17" value="检查用户是否存在" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
44+
<mxGeometry x="380" y="200" width="137.5" height="40" as="geometry"/>
45+
</mxCell>
46+
<mxCell id="24" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="19" target="23">
47+
<mxGeometry relative="1" as="geometry"/>
48+
</mxCell>
49+
<mxCell id="19" value="检查密码是否正确" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
50+
<mxGeometry x="620" y="200" width="100" height="40" as="geometry"/>
51+
</mxCell>
52+
<mxCell id="29" value="普通" style="edgeStyle=none;html=1;" edge="1" parent="1" source="23" target="28">
53+
<mxGeometry relative="1" as="geometry"/>
54+
</mxCell>
55+
<mxCell id="31" value="管理员" style="edgeStyle=none;html=1;" edge="1" parent="1" source="23" target="30">
56+
<mxGeometry relative="1" as="geometry"/>
57+
</mxCell>
58+
<mxCell id="23" value="检查角色" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
59+
<mxGeometry x="760" y="205" width="90" height="30" as="geometry"/>
60+
</mxCell>
61+
<mxCell id="28" value="进入" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
62+
<mxGeometry x="982.5" y="80" width="60" height="35" as="geometry"/>
63+
</mxCell>
64+
<mxCell id="30" value="管理员" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="1">
65+
<mxGeometry x="970" y="290" width="85" height="30" as="geometry"/>
66+
</mxCell>
67+
</root>
68+
</mxGraphModel>
69+
</diagram>
70+
</mxfile>

0 commit comments

Comments
 (0)