ソースを参照

3.定时消息发送列表增加字段重复策略,增加每周、每月、每天、每年重复

seimin 3 年 前
コミット
f1342de810

+ 0 - 2
src/app/views/hushijiandan/hushijiandan.component.ts

@@ -27,11 +27,9 @@ import {
27 27
   format,
28 28
   getMinutes,
29 29
   setMinutes,
30
-  setSeconds,
31 30
   addDays,
32 31
   differenceInCalendarDays,
33 32
   getHours,
34
-  getDate,
35 33
 } from "date-fns";
36 34
 // 日期禁用
37 35
 function range(start: number, end: number): number[] {

+ 51 - 9
src/app/views/timing-message-sending/timing-message-sending.component.html

@@ -12,10 +12,11 @@
12 12
             <th nzWidth="5%">序号</th>
13 13
             <th nzWidth="10%">标题</th>
14 14
             <th nzWidth="25%">发送内容</th>
15
+            <th nzWidth="10%">重复策略</th>
15 16
             <th nzWidth="15%">定时发送时间</th>
16 17
             <th nzWidth="10%">状态</th>
17 18
             <th nzWidth="10%">接收人</th>
18
-            <th nzWidth="25%">操作</th>
19
+            <th nzWidth="15%">操作</th>
19 20
           </tr>
20 21
         </thead>
21 22
         <tbody>
@@ -23,7 +24,18 @@
23 24
             <td>{{ i+1 }}</td>
24 25
             <td>{{ data.title }}</td>
25 26
             <td>{{ data.content }}</td>
26
-            <td>{{ data.executeTime|date:'HH:mm:ss' }}</td>
27
+            <td [ngSwitch]="data.timeStep">
28
+              <ng-container *ngSwitchCase="'day'">每日</ng-container>
29
+              <ng-container *ngSwitchCase="'week'">每周</ng-container>
30
+              <ng-container *ngSwitchCase="'month'">每月</ng-container>
31
+              <ng-container *ngSwitchCase="'year'">每年</ng-container>
32
+            </td>
33
+            <td [ngSwitch]="data.timeStep">
34
+              <ng-container *ngSwitchCase="'day'">{{ data.executeTime|date:'HH时mm分' }}</ng-container>
35
+              <ng-container *ngSwitchCase="'week'">{{data.weekName}} {{ data.executeTime|date:'HH时mm分' }}</ng-container>
36
+              <ng-container *ngSwitchCase="'month'">{{data.extra1}}日 {{ data.executeTime|date:'HH时mm分' }}</ng-container>
37
+              <ng-container *ngSwitchCase="'year'">{{ data.executeTime|date:'MM月dd日HH时mm分' }}</ng-container>
38
+            </td>
27 39
             <td>{{ data.active?'开启':'关闭' }}</td>
28 40
             <td>{{ data.usersName }}</td>
29 41
             <td>
@@ -60,20 +72,50 @@
60 72
             </nz-form-control>
61 73
           </nz-form-item>
62 74
           <nz-form-item>
63
-            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="xxx">重复策略</nz-form-label>
75
+            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="timeStep">重复策略</nz-form-label>
64 76
             <nz-form-control nzErrorTip="请选择重复策略!">
65
-              <nz-radio-group formControlName="xxx">
66
-                <label nz-radio [nzValue]="1">每天</label>
67
-                <label nz-radio [nzValue]="2">每周</label>
68
-                <label nz-radio [nzValue]="3">每月</label>
69
-                <label nz-radio [nzValue]="4">每年</label>
77
+              <nz-radio-group formControlName="timeStep" (ngModelChange)="timeStepChange($event)">
78
+                <label nz-radio nzValue="day">每天</label>
79
+                <label nz-radio nzValue="week">每周</label>
80
+                <label nz-radio nzValue="month">每月</label>
81
+                <label nz-radio nzValue="year">每年</label>
70 82
               </nz-radio-group>
71 83
             </nz-form-control>
72 84
           </nz-form-item>
85
+          <nz-form-item *ngIf="validateForm.value.timeStep == 'week'">
86
+            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doWeek">计划执行周(每周)</nz-form-label>
87
+            <nz-form-control nzErrorTip="请选择周!">
88
+              <nz-select formControlName="doWeek" nzPlaceHolder="请选择周">
89
+                <nz-option nzValue="1" nzLabel="周一"></nz-option>
90
+                <nz-option nzValue="2" nzLabel="周二"></nz-option>
91
+                <nz-option nzValue="3" nzLabel="周三"></nz-option>
92
+                <nz-option nzValue="4" nzLabel="周四"></nz-option>
93
+                <nz-option nzValue="5" nzLabel="周五"></nz-option>
94
+                <nz-option nzValue="6" nzLabel="周六"></nz-option>
95
+                <nz-option nzValue="7" nzLabel="周日"></nz-option>
96
+              </nz-select>
97
+            </nz-form-control>
98
+          </nz-form-item>
99
+          <nz-form-item *ngIf="validateForm.value.timeStep == 'month'">
100
+            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doMonth">计划执行(每月)</nz-form-label>
101
+            <nz-form-control nzErrorTip="请选择日!">
102
+              <nz-select formControlName="doMonth" nzPlaceHolder="请选择日">
103
+                <nz-option nzValue="{{item}}" nzLabel="{{item}}号" *ngFor="let item of months">
104
+                </nz-option>
105
+              </nz-select>
106
+            </nz-form-control>
107
+          </nz-form-item>
108
+          <nz-form-item *ngIf="validateForm.value.timeStep == 'year'">
109
+            <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="doYear">计划执行(每年)</nz-form-label>
110
+            <nz-form-control nzErrorTip="请选择月日!">
111
+              <nz-date-picker nzFormat="MM-dd" formControlName="doYear" nzPlaceHolder="请选择月日"></nz-date-picker>
112
+            </nz-form-control>
113
+          </nz-form-item>
73 114
           <nz-form-item>
74 115
             <nz-form-label [nzSm]="24" [nzXs]="24" nzRequired nzFor="executeTime">定时发送时间</nz-form-label>
75 116
             <nz-form-control nzErrorTip="请选择定时发送时间!">
76
-              <nz-time-picker class="executeTime" formControlName="executeTime" nzPlaceHolder="请选择定时发送时间">
117
+              <nz-time-picker nzFormat="HH:mm" class="executeTime" formControlName="executeTime"
118
+                nzPlaceHolder="请选择定时发送时间" [nzAllowEmpty]="false">
77 119
               </nz-time-picker>
78 120
             </nz-form-control>
79 121
           </nz-form-item>

+ 3 - 0
src/app/views/timing-message-sending/timing-message-sending.component.less

@@ -6,6 +6,9 @@
6 6
   .ant-calendar-picker {
7 7
   width: 100% !important;
8 8
 }
9
+::ng-deep .ant-calendar-picker-input {
10
+  width: 410px !important;
11
+}
9 12
 
10 13
 .save {
11 14
   position: fixed;

+ 82 - 3
src/app/views/timing-message-sending/timing-message-sending.component.ts

@@ -1,11 +1,17 @@
1 1
 import { Component, OnInit, ViewChild } from "@angular/core";
2 2
 import { ActivatedRoute } from "@angular/router";
3
-import { FormBuilder, Validators, FormGroup } from "@angular/forms";
3
+import {
4
+  FormBuilder,
5
+  Validators,
6
+  FormGroup,
7
+  FormControl,
8
+} from "@angular/forms";
4 9
 
5 10
 import { MainService } from "../../services/main.service";
6 11
 import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
7 12
 import { ToolService } from "../../services/tool.service";
8 13
 import { NzMessageService } from "ng-zorro-antd";
14
+import { format } from "date-fns";
9 15
 @Component({
10 16
   selector: "app-timing-message-sending",
11 17
   templateUrl: "./timing-message-sending.component.html",
@@ -141,6 +147,18 @@ export class TimingMessageSendingComponent implements OnInit {
141 147
         if (data.status == 200) {
142 148
           this.listOfData = data.list;
143 149
           this.listOfData.forEach((item) => {
150
+            if (item.timeStep == "week") {
151
+              let weeks = [
152
+                "周一",
153
+                "周二",
154
+                "周三",
155
+                "周四",
156
+                "周五",
157
+                "周六",
158
+                "周日",
159
+              ];
160
+              item.weekName = weeks[item.extra1 - 1];
161
+            }
144 162
             item.usersName = item.users.map((value) => value.name).join();
145 163
           });
146 164
           this.listLength = data.totalNum;
@@ -156,12 +174,47 @@ export class TimingMessageSendingComponent implements OnInit {
156 174
   initForm() {
157 175
     this.validateForm = this.fb.group({
158 176
       title: [null, [Validators.required]], //标题
159
-      xxx: [1, [Validators.required]], //重复策略
177
+      timeStep: ["day", [Validators.required]], //重复策略
160 178
       executeTime: [null, [Validators.required]], //定时发送时间
161 179
       active: [false, [Validators.required]], //是否启用
162 180
       userIds: [null, [Validators.required]], //接收人
163 181
     });
164 182
   }
183
+  //修改重复策略
184
+  months = [...Array(32).keys()].slice(1);
185
+  timeStepChange(e) {
186
+    switch (e) {
187
+      case "day":
188
+        this.validateForm.removeControl("doWeek");
189
+        this.validateForm.removeControl("doMonth");
190
+        this.validateForm.removeControl("doYear");
191
+        break;
192
+      case "week":
193
+        this.validateForm.addControl(
194
+          "doWeek",
195
+          new FormControl(null, Validators.required)
196
+        );
197
+        this.validateForm.removeControl("doMonth");
198
+        this.validateForm.removeControl("doYear");
199
+        break;
200
+      case "month":
201
+        this.validateForm.addControl(
202
+          "doMonth",
203
+          new FormControl(null, Validators.required)
204
+        );
205
+        this.validateForm.removeControl("doWeek");
206
+        this.validateForm.removeControl("doYear");
207
+        break;
208
+      case "year":
209
+        this.validateForm.addControl(
210
+          "doYear",
211
+          new FormControl(null, Validators.required)
212
+        );
213
+        this.validateForm.removeControl("doWeek");
214
+        this.validateForm.removeControl("doMonth");
215
+        break;
216
+    }
217
+  }
165 218
 
166 219
   // 表单提交
167 220
   submitForm(): void {
@@ -174,7 +227,7 @@ export class TimingMessageSendingComponent implements OnInit {
174 227
       this.btnLoading = false;
175 228
       return;
176 229
     }
177
-    let postData = {
230
+    let postData: any = {
178 231
       title: this.validateForm.value.title,
179 232
       executeTime: new Date(this.validateForm.value.executeTime).getTime(),
180 233
       userIds: this.validateForm.value.userIds.join(),
@@ -182,7 +235,22 @@ export class TimingMessageSendingComponent implements OnInit {
182 235
       content: this.dataContent.content,
183 236
       key: this.dataContent.key,
184 237
       id: this.dataContent.id,
238
+      timeStep: this.validateForm.value.timeStep,
185 239
     };
240
+    if (this.validateForm.value.timeStep == "day") {
241
+      delete postData.extra1;
242
+    } else if (this.validateForm.value.timeStep == "week") {
243
+      postData.extra1 = this.validateForm.value.doWeek;
244
+    } else if (this.validateForm.value.timeStep == "month") {
245
+      postData.extra1 = this.validateForm.value.doMonth;
246
+    } else if (this.validateForm.value.timeStep == "year") {
247
+      delete postData.extra1;
248
+      postData.executeTime = new Date(
249
+        format(this.validateForm.value.doYear, "yyyy-MM-dd") +
250
+          " " +
251
+          format(new Date(this.validateForm.value.executeTime), "HH:mm:ss")
252
+      ).getTime();
253
+    }
186 254
     this.mainService
187 255
       .simplePost("updData", "messageJob", postData)
188 256
       .subscribe((data) => {
@@ -205,6 +273,17 @@ export class TimingMessageSendingComponent implements OnInit {
205 273
     this.validateForm.controls.executeTime.setValue(new Date(data.executeTime)); //定时发送时间
206 274
     this.validateForm.controls.title.setValue(data.title); //标题
207 275
     this.validateForm.controls.active.setValue(data.active); //是否启用
276
+    this.timeStepChange(data.timeStep);
277
+    this.validateForm.controls.timeStep.setValue(data.timeStep); //重复策略
278
+    if (data.timeStep == "year") {
279
+      this.validateForm.controls.doYear.setValue(
280
+        format(data.executeTime, "yyyy-MM-dd HH:mm:ss")
281
+      );
282
+    } else if (data.timeStep == "month") {
283
+      this.validateForm.controls.doMonth.setValue(data.extra1);
284
+    } else if (data.timeStep == "week") {
285
+      this.validateForm.controls.doWeek.setValue(data.extra1);
286
+    }
208 287
     // --------接收人---
209 288
     this.maskFlag = this.message.loading("正在加载中..", {
210 289
       nzDuration: 0,