FormBuilderInputEditor.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="form-builder-editor"
  3. :class="customClass">
  4. <p v-text="label" />
  5. <q-editor v-if="!disable && !readonly"
  6. ref="editor"
  7. v-model="inputData"
  8. :class="customClass"
  9. :content-class="customClass"
  10. :name="name"
  11. :dense="$q.screen.lt.md"
  12. :toolbar="[
  13. [
  14. {
  15. label: $q.lang.editor.align,
  16. icon: $q.iconSet.editor.align,
  17. fixedLabel: true,
  18. options: ['left', 'center', 'right', 'justify']
  19. }
  20. ],
  21. ['bold', 'italic', 'strike', 'underline', 'subscript', 'superscript', 'colorpicker'],
  22. ['token', 'hr', 'link', 'custom_btn'],
  23. ['print', 'fullscreen'],
  24. [
  25. {
  26. label: $q.lang.editor.formatting,
  27. icon: $q.iconSet.editor.formatting,
  28. list: 'no-icons',
  29. options: ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'code']
  30. },
  31. {
  32. label: $q.lang.editor.fontSize,
  33. icon: $q.iconSet.editor.fontSize,
  34. fixedLabel: true,
  35. fixedIcon: true,
  36. list: 'no-icons',
  37. options: [
  38. 'size-1',
  39. 'size-2',
  40. 'size-3',
  41. 'size-4',
  42. 'size-5',
  43. 'size-6',
  44. 'size-7'
  45. ]
  46. },
  47. {
  48. label: $q.lang.editor.defaultFont,
  49. icon: $q.iconSet.editor.font,
  50. fixedIcon: true,
  51. list: 'no-icons',
  52. options: [
  53. 'default_font',
  54. 'arial',
  55. 'arial_black',
  56. 'comic_sans',
  57. 'courier_new',
  58. 'impact',
  59. 'lucida_grande',
  60. 'times_new_roman',
  61. 'verdana'
  62. ]
  63. },
  64. 'removeFormat'
  65. ],
  66. ['quote', 'unordered', 'ordered', 'outdent', 'indent'],
  67. ['undo', 'redo'],
  68. ['viewsource']
  69. ]"
  70. :fonts="{
  71. IRANSans: 'IRANSans',
  72. arial: 'Arial',
  73. arial_black: 'Arial Black',
  74. comic_sans: 'Comic Sans MS',
  75. courier_new: 'Courier New',
  76. impact: 'Impact',
  77. lucida_grande: 'Lucida Grande',
  78. times_new_roman: 'Times New Roman',
  79. verdana: 'Verdana',
  80. }"
  81. @update:model-value="change($event)"
  82. @click="onClick"
  83. @paste="onPaste">
  84. <template v-slot:colorpicker>
  85. <q-btn-dropdown ref="token"
  86. dense
  87. no-caps
  88. no-wrap
  89. unelevated
  90. color="white"
  91. text-color="primary"
  92. label="رنگ"
  93. size="sm">
  94. <q-list dense>
  95. <q-item tag="label"
  96. clickable
  97. @click="setColor('backColor', highlight)">
  98. <q-item-section side>
  99. <q-icon name="highlight" />
  100. </q-item-section>
  101. <q-item-section>
  102. <q-color v-model="highlight"
  103. default-view="palette"
  104. no-header
  105. no-footer
  106. :palette="[
  107. '#ffccccaa', '#ffe6ccaa', '#ffffccaa', '#ccffccaa',
  108. '#ccffe6aa', '#ccffffaa', '#cce6ffaa', '#ccccffaa', '#e6ccffaa', '#ffccffaa', '#ff0000aa', '#ff8000aa', '#ffff00aa', '#00ff00aa', '#00ff80aa', '#00ffffaa', '#0080ffaa', '#0000ffaa', '#8000ffaa', '#ff00ffaa'
  109. ]"
  110. class="my-picker" />
  111. </q-item-section>
  112. </q-item>
  113. <q-item tag="label"
  114. clickable
  115. @click="setColor('foreColor', foreColor)">
  116. <q-item-section side>
  117. <q-icon name="format_paint" />
  118. </q-item-section>
  119. <q-item-section>
  120. <q-color v-model="foreColor"
  121. no-header
  122. no-footer
  123. default-view="palette"
  124. :palette="[
  125. '#ff0000', '#ff8000', '#ffff00', '#00ff00', '#00ff80', '#00ffff', '#0080ff', '#0000ff', '#8000ff', '#ff00ff'
  126. ]"
  127. class="my-picker" />
  128. </q-item-section>
  129. </q-item>
  130. </q-list>
  131. </q-btn-dropdown>
  132. </template>
  133. </q-editor>
  134. <!--eslint-disable-next-line-->
  135. <div v-else v-html="inputData" />
  136. </div>
  137. </template>
  138. <script>
  139. import { inputMixin } from 'quasar-form-builder'
  140. export default {
  141. name: 'FormBuilderInputEditor',
  142. mixins: [inputMixin],
  143. props: {
  144. name: {
  145. default: '',
  146. type: String
  147. },
  148. value: {
  149. default: '',
  150. type: [String, Number, Boolean]
  151. }
  152. },
  153. data () {
  154. return {
  155. inputData: '',
  156. foreColor: '#000000',
  157. highlight: '#ffff00aa'
  158. }
  159. },
  160. watch: {
  161. value(newValue) {
  162. if (!newValue) {
  163. this.inputData = ''
  164. }
  165. }
  166. },
  167. created() {
  168. if (!this.inputData) {
  169. this.inputData = ''
  170. }
  171. },
  172. methods: {
  173. onPaste () {
  174. this.inputData = this.inputData.replaceAll(/<!--\[if .*endif\]-->/gms, 'ferret')
  175. },
  176. setColor (cmd, name) {
  177. const edit = this.$refs.editor
  178. this.$refs.token.hide()
  179. edit.caret.restore()
  180. edit.runCmd(cmd, name)
  181. edit.focus()
  182. }
  183. }
  184. }
  185. </script>