Roles.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import format from 'date-fns/format';
  17. import { BaseEntity } from './BaseEntity';
  18. export class Roles extends BaseEntity {
  19. name!: String;
  20. dynamic!: String;
  21. filters!: String;
  22. orgIdsList!: String;
  23. resumeTime!: String;
  24. suspendTime!: String;
  25. isdefault!: String;
  26. switch_dynamic: boolean = false;
  27. picker_resumeTime: Date = new Date(format(new Date(), 'yyyy-MM-dd 00:00:00'));
  28. picker_suspendTime: Date = new Date(format(new Date(), 'yyyy-MM-dd 00:00:00'));
  29. constructor() {
  30. super();
  31. this.status = 1;
  32. }
  33. override init(data: any): void {
  34. Object.assign(this, data);
  35. if (this.status == 1) {
  36. this.switch_status = true;
  37. }
  38. if (this.dynamic == '1') {
  39. this.switch_dynamic = true;
  40. }
  41. if (this.resumeTime != '') {
  42. this.picker_resumeTime = new Date(format(new Date(), `yyyy-MM-dd ${this.resumeTime}:00`));
  43. }
  44. if (this.suspendTime != '') {
  45. this.picker_suspendTime = new Date(format(new Date(), `yyyy-MM-dd ${this.suspendTime}:00`));
  46. }
  47. }
  48. override trans(): void {
  49. if (this.switch_status) {
  50. this.status = 1;
  51. } else {
  52. this.status = 0;
  53. }
  54. if (this.switch_dynamic) {
  55. this.dynamic = '1';
  56. } else {
  57. this.dynamic = '0';
  58. }
  59. if (this.picker_resumeTime) {
  60. this.resumeTime = format(this.picker_resumeTime, 'HH:mm');
  61. }
  62. if (this.picker_suspendTime) {
  63. this.suspendTime = format(this.picker_suspendTime, 'HH:mm');
  64. }
  65. }
  66. }