前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PrintContainer.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // 定义 PrintDevice 枚举
  2. enum PrintDevice {
  3. Printer,
  4. Other
  5. }
  6. // 模拟 ImageBrush 类
  7. class ImageBrush {
  8. ImageSource: string | null = null;
  9. }
  10. // 模拟 Brush 类
  11. class Brush { }
  12. // 模拟 DependencyProperty 类
  13. class DependencyProperty {
  14. static Register(name: string, type: any, ownerType: any, metadata: any) {
  15. return new DependencyProperty();
  16. }
  17. }
  18. // 模拟 UIPropertyMetadata 类
  19. class UIPropertyMetadata {
  20. constructor(defaultValue: any, callback?: any) { }
  21. }
  22. // 模拟 Application 类
  23. class Application {
  24. static Current = new Application();
  25. TryFindResource(resource: any): any {
  26. return null;
  27. }
  28. }
  29. // 模拟 ContentControl 类
  30. class ContentControl {
  31. Background: Brush | null = null;
  32. VisualParent: any | null = null;
  33. InvalidateVisual() { }
  34. ActualWidth = 0;
  35. ActualHeight = 0;
  36. Content: any | null = null;
  37. }
  38. // 模拟 Window 类
  39. class Window {
  40. Content: any | null = null;
  41. ShowInTaskbar = false;
  42. WindowState: any;
  43. Top = 0;
  44. Left = 0;
  45. constructor() { }
  46. Show() { }
  47. Close() { }
  48. }
  49. // 模拟 XpsDocument 类
  50. class XpsDocument {
  51. CoreDocumentProperties: {
  52. Title: string;
  53. Description: string;
  54. ContentType: string;
  55. Subject: string;
  56. } = {
  57. Title: '',
  58. Description: '',
  59. ContentType: '',
  60. Subject: ''
  61. };
  62. constructor(fileName: string, access: any) { }
  63. Close() { }
  64. }
  65. // 模拟 XpsDocumentWriter 类
  66. class XpsDocumentWriter {
  67. static CreateXpsDocumentWriter(xd: XpsDocument) {
  68. return new XpsDocumentWriter();
  69. }
  70. Write(visual: any) { }
  71. }
  72. // 模拟 RenderTargetBitmap 类
  73. class RenderTargetBitmap {
  74. constructor(width: number, height: number, dpiX: number, dpiY: number, format: any) { }
  75. Render(visual: any) { }
  76. }
  77. // 模拟 ImageSource 类
  78. class ImageSource { }
  79. class PrintContainer extends ContentControl {
  80. private _documentId: string | null = null;
  81. DocumentName: string;
  82. Description: string;
  83. Device: PrintDevice;
  84. IsNotingPreview: boolean;
  85. BackgroundImage: ImageBrush | null = null;
  86. BackgroundBrush: string;
  87. static readonly BackgroundBrushProperty = DependencyProperty.Register(
  88. "BackgroundBrush",
  89. String,
  90. PrintContainer,
  91. new UIPropertyMetadata('', (sender: any, e: any) => {
  92. const element = sender as PrintContainer;
  93. if (!element || !e.NewValue) return;
  94. element.Background = Application.Current.TryFindResource(e.NewValue) as Brush;
  95. })
  96. );
  97. static {
  98. // 模拟重写默认样式键
  99. }
  100. constructor() {
  101. super();
  102. this.DocumentName = "默认表单";
  103. this.Description = "";
  104. this.Device = PrintDevice.Printer;
  105. this.IsNotingPreview = false;
  106. this.BackgroundBrush = '';
  107. }
  108. get DocumentId(): string {
  109. if (!this._documentId) {
  110. return this.constructor.name;
  111. }
  112. return this._documentId;
  113. }
  114. set DocumentId(value: string) {
  115. this._documentId = value;
  116. }
  117. PrintToXps(): { path: string } {
  118. const tempDir = `${process.cwd()}/temp`;
  119. const filePath = `${tempDir}/${Math.random().toString(36).substring(7)}`;
  120. // 模拟文件操作
  121. return { path: filePath };
  122. }
  123. PrintToPng(): ImageSource {
  124. return new ImageSource();
  125. }
  126. }
  127. export { PrintContainer };