index.html.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * The watermark view file of watermark module of XXB.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd., www.zentao.net)
  6. * @license ZOSL (https://zpl.pub/page/zoslv1.html)
  7. */
  8. ?>
  9. <?php include '../../common/view/header.html.php';?>
  10. <div style="display: flex;">
  11. <div class='panel'>
  12. <div class='panel-heading'>
  13. <strong><?php echo $lang->watermark->common;?></strong>
  14. </div>
  15. <form method="post" class="form-ajax" id="watermark-ajax-form">
  16. <table class="table table-form">
  17. <tr>
  18. <th class="w-120px"><?php echo $lang->watermark->switch?></th>
  19. <td class='w-p50'>
  20. <?= $type == 'edit'
  21. ? html::radio('enabled', $lang->watermark->switchList, $enabled)
  22. : $lang->watermark->switchList[$enabled]
  23. ?>
  24. </td>
  25. <td></td>
  26. </tr>
  27. <?php if(($enabled == 1 && $type !== 'edit') || $type == 'edit'): ?>
  28. <tr id="watermark-tr">
  29. <th class="w-120px"><?= $lang->watermark->content; ?></th>
  30. <td class="w-p50">
  31. <?= html::textarea('content', $content, ('rows="3" class="form-control"' . ($type === 'edit' ? '' : ' disabled'))); ?>
  32. </td>
  33. <td></td>
  34. </tr>
  35. <?php endif; ?>
  36. <?php if($type == 'edit'): ?>
  37. <tr id="watermark-tip-tr">
  38. <th></th>
  39. <td>
  40. <div>
  41. <p><i class="icon icon-exclamation-sign" style="color: orange; margin-right: 4px;"></i><?= $lang->watermark->varTip; ?></p>
  42. <table class="table-bordered">
  43. <tbody>
  44. <tr>
  45. <th>displayName</th>
  46. <td><?= $lang->watermark->displayName; ?></td>
  47. </tr>
  48. <tr>
  49. <th>account</th>
  50. <td><?= $lang->watermark->account; ?></td>
  51. </tr>
  52. <tr>
  53. <th>email</th>
  54. <td><?= $lang->watermark->email; ?></td>
  55. </tr>
  56. <tr>
  57. <th>phone</th>
  58. <td><?= $lang->watermark->phone; ?></td>
  59. </tr>
  60. <tr>
  61. <th>date</th>
  62. <td><?= $lang->watermark->date; ?></td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. </div>
  67. </td>
  68. <td></td>
  69. </tr>
  70. <?php endif; ?>
  71. <tr>
  72. <?php if($type == 'edit'): ?>
  73. <th></th>
  74. <td><?= html::submitButton(); ?>&nbsp;&nbsp;&nbsp;<?= html::backButton(); ?></td>
  75. <td></td>
  76. <?php else: ?>
  77. <th></th>
  78. <td colspan="2"><?= '<a class="btn btn-primary" href="' . helper::createLink('watermark', 'index', 'type=edit') . '">' . $lang->edit; ?></td>
  79. <td></td>
  80. <?php endif; ?>
  81. </tr>
  82. </table>
  83. </form>
  84. </div>
  85. <?php if(($enabled == 1 && $type !== 'edit') || $type == 'edit'): ?>
  86. <div id="watermark-preview" class='panel' style="margin-left: 20px;">
  87. <div class='panel-heading'>
  88. <strong><?= $lang->watermark->preview; ?></strong>
  89. </div>
  90. <div id="preview-container"></div>
  91. </div>
  92. <?php endif;?>
  93. </div>
  94. <style>
  95. #preview-container {
  96. position: relative;
  97. min-width: 600px;
  98. min-height: 600px;
  99. }
  100. </style>
  101. <?php
  102. $jsRoot = $webRoot . "js/";
  103. js::import($jsRoot . 'watermark/index.iife.min.js');
  104. ?>
  105. <script>
  106. const displayName = `<?= $displayName; ?>`;
  107. const account = `<?= $account; ?>`;
  108. const email = `<?= $email; ?>`;
  109. const phone = `<?= $phone; ?>`;
  110. let watermark = null;
  111. function setContentPreview(value)
  112. {
  113. const parent = document.querySelector('#preview-container');
  114. if(!value || !parent) return;
  115. const content = value.replace(/\$displayName/g, displayName)
  116. .replace(/\$account/g, account)
  117. .replace(/\$email/g, email)
  118. .replace(/\$phone/g, phone)
  119. .replace(/\$date/g, getCurrentDateFormatted())
  120. .split('\n')
  121. .filter(line => line.trim().length > 0)
  122. .join('\n');
  123. if(watermark) watermark.destroy();
  124. watermark = new WatermarkPlus.Watermark({
  125. content,
  126. contentType: 'multi-line-text',
  127. rotate: 35,
  128. parent: parent,
  129. fontSize: '20px',
  130. fontColor: 'rgba(0,0,0,0.15)',
  131. zIndex: 0,
  132. })
  133. watermark.create();
  134. }
  135. function getCurrentDateFormatted()
  136. {
  137. const today = new Date();
  138. const year = today.getFullYear();
  139. const month = ('0' + (today.getMonth() + 1)).slice(-2); // 月份是从0开始的,所以需要+1
  140. const day = ('0' + today.getDate()).slice(-2); // 日期
  141. return `${year}-${month}-${day}`;
  142. }
  143. function showWatermarkDom()
  144. {
  145. $('#watermark-tr').removeClass('hidden');
  146. $('#watermark-tip-tr').removeClass('hidden');
  147. $('#watermark-preview').removeClass('hidden');
  148. }
  149. function hideWatermarkDom()
  150. {
  151. $('#watermark-tr').addClass('hidden');
  152. $('#watermark-tip-tr').addClass('hidden');
  153. $('#watermark-preview').addClass('hidden');
  154. }
  155. function toggleWatermarkDom(enabled)
  156. {
  157. if(enabled == 1) showWatermarkDom();
  158. else hideWatermarkDom();
  159. }
  160. $(() => {
  161. $.setAjaxForm('#watermark-ajax-form');
  162. const $content = $('#content');
  163. $content.on('input', function() {
  164. setContentPreview($(this).val());
  165. });
  166. setContentPreview($content.val());
  167. $('input[name="enabled"]').on('change', function() {
  168. toggleWatermarkDom($(this).val());
  169. });
  170. const enabled = $('input[name="enabled"]:checked').length
  171. ? $('input[name="enabled"]:checked').val()
  172. : <?= $enabled; ?>;
  173. toggleWatermarkDom(enabled);
  174. });
  175. </script>
  176. <?php include '../../common/view/footer.html.php';?>