FullTextSettings.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <el-dialog
  3. custom-class="full-text-settings"
  4. width="570px"
  5. :close-on-click-modal="false"
  6. :visible="visible"
  7. :before-close="handleClose"
  8. title="样式调整"
  9. >
  10. <el-form ref="form" :model="unified_attrib" label-width="80px" size="small">
  11. <el-form-item label="主题色">
  12. <div class="color-group">
  13. <ColorPicker v-model="unified_attrib.topic_color" :type="2" />
  14. <span>辅助色</span>
  15. <el-color-picker v-model="unified_attrib.assist_color" />
  16. <span class="link" @click="generateAssistColor">自动生成辅助色</span>
  17. </div>
  18. <el-button
  19. type="primary"
  20. class="row-button"
  21. @click="
  22. applySingleAttrToSelectedComponents('topic_color');
  23. applySingleAttrToSelectedComponents('assist_color');
  24. "
  25. >
  26. 应用选中组件
  27. </el-button>
  28. <el-button
  29. type="primary"
  30. class="row-button"
  31. @click="
  32. applySingleAttrToAllComponents('topic_color');
  33. applySingleAttrToAllComponents('assist_color');
  34. "
  35. >
  36. 应用整页
  37. </el-button>
  38. </el-form-item>
  39. <el-form-item label="字体">
  40. <el-select v-model="unified_attrib.font" placeholder="请选择字体">
  41. <el-option v-for="{ label, value } in fontList" :key="value" :label="label" :value="value" />
  42. </el-select>
  43. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('font')">
  44. 应用选中组件
  45. </el-button>
  46. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('font')">
  47. 应用整页
  48. </el-button>
  49. </el-form-item>
  50. <el-form-item label="字号">
  51. <el-select v-model="unified_attrib.font_size" placeholder="请选择字号">
  52. <el-option v-for="size in fontSizeList" :key="size" :label="size" :value="size" />
  53. </el-select>
  54. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('font_size')">
  55. 应用选中组件
  56. </el-button>
  57. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('font_size')">
  58. 应用整页
  59. </el-button>
  60. </el-form-item>
  61. <el-form-item label="拼音字号">
  62. <el-select v-model="unified_attrib.pinyin_size" placeholder="请选择拼音字号">
  63. <el-option v-for="size in fontSizeList" :key="size" :label="size" :value="size" />
  64. </el-select>
  65. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('pinyin_size')">
  66. 应用选中组件
  67. </el-button>
  68. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('pinyin_size')">
  69. 应用整页
  70. </el-button>
  71. </el-form-item>
  72. <el-form-item label="行距">
  73. <el-input-number v-model="unified_attrib.line_height" :min="0" :max="20" :step="0.1" />
  74. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('line_height')">
  75. 应用选中组件
  76. </el-button>
  77. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('line_height')">
  78. 应用整页
  79. </el-button>
  80. </el-form-item>
  81. <el-form-item label="文字颜色">
  82. <ColorPicker v-model="unified_attrib.text_color" :type="1" />
  83. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('text_color')">
  84. 应用选中组件
  85. </el-button>
  86. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('text_color')">
  87. 应用整页
  88. </el-button>
  89. </el-form-item>
  90. <el-form-item label="对齐方式">
  91. <el-select v-model="unified_attrib.align" placeholder="请选择对齐方式">
  92. <el-option label="左对齐" value="LEFT" />
  93. <el-option label="居中" value="MIDDLE" />
  94. <el-option label="右对齐" value="RIGHT" />
  95. </el-select>
  96. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('align')">
  97. 应用选中组件
  98. </el-button>
  99. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('align')">
  100. 应用整页
  101. </el-button>
  102. </el-form-item>
  103. <el-form-item label="拼音">
  104. <el-switch v-model="unified_attrib.view_pinyin" active-value="true" inactive-value="false" />
  105. <el-button type="primary" class="row-button" @click="applySingleAttrToSelectedComponents('view_pinyin')">
  106. 应用选中组件
  107. </el-button>
  108. <el-button type="primary" class="row-button" @click="applySingleAttrToAllComponents('view_pinyin')">
  109. 应用整页
  110. </el-button>
  111. </el-form-item>
  112. <el-form-item label="拼音位置">
  113. <el-radio-group v-model="unified_attrib.pinyin_position" :disabled="!isEnable(unified_attrib.view_pinyin)">
  114. <el-radio v-for="{ value, label } in pinyinPositionList" :key="value" :label="value">
  115. {{ label }}
  116. </el-radio>
  117. </el-radio-group>
  118. <el-button
  119. type="primary"
  120. class="row-button"
  121. :disabled="!isEnable(unified_attrib.view_pinyin)"
  122. @click="applySingleAttrToSelectedComponents('pinyin_position')"
  123. >
  124. 应用选中组件
  125. </el-button>
  126. <el-button
  127. type="primary"
  128. :disabled="!isEnable(unified_attrib.view_pinyin)"
  129. class="row-button"
  130. @click="applySingleAttrToAllComponents('pinyin_position')"
  131. >
  132. 应用整页
  133. </el-button>
  134. </el-form-item>
  135. </el-form>
  136. <div slot="footer" class="dialog-footer">
  137. <el-button @click="handleClose">取 消</el-button>
  138. <el-button type="primary" @click="applyToSelectedComponents">应用选中组件</el-button>
  139. <el-button type="primary" @click="confirm">应用整页</el-button>
  140. </div>
  141. </el-dialog>
  142. </template>
  143. <script>
  144. import ColorPicker from '@/components/ColorPicker.vue';
  145. import { pinyinPositionList, fontList, fontSizeList, isEnable } from '@/views/book/courseware/data/common';
  146. import { GetBookUnifiedAttrib } from '@/api/book';
  147. import { unified_attrib } from '@/common/data';
  148. import { ToAuxiliaryColor } from '@/api/app';
  149. export default {
  150. name: 'FullTextSettings',
  151. components: {
  152. ColorPicker,
  153. },
  154. props: {
  155. visible: {
  156. type: Boolean,
  157. required: true,
  158. },
  159. settings: {
  160. type: Object,
  161. default: () => unified_attrib,
  162. },
  163. bookId: {
  164. type: String,
  165. required: true,
  166. },
  167. },
  168. data() {
  169. return {
  170. unified_attrib,
  171. fontSizeList,
  172. pinyinPositionList,
  173. fontList,
  174. isEnable,
  175. };
  176. },
  177. watch: {
  178. visible(val) {
  179. if (val) {
  180. this.$set(this, 'unified_attrib', { ...this.unified_attrib, ...this.settings });
  181. }
  182. },
  183. },
  184. created() {
  185. this.getBookUnifiedAttr();
  186. },
  187. methods: {
  188. getBookUnifiedAttr() {
  189. GetBookUnifiedAttrib({ book_id: this.bookId }).then(({ content }) => {
  190. if (content && (this.settings === null || Object.keys(this.settings).length <= 0)) {
  191. this.unified_attrib = JSON.parse(content);
  192. }
  193. });
  194. },
  195. /* eslint-disable no-bitwise */
  196. /**
  197. * 根据主题色自动生成辅助色
  198. */
  199. generateAssistColor() {
  200. const bigint = parseInt(this.unified_attrib.topic_color.replace('#', ''), 16);
  201. const r = (bigint >> 16) & 255;
  202. const g = (bigint >> 8) & 255;
  203. const b = bigint & 255;
  204. ToAuxiliaryColor({ r, g, b }).then(({ color: { r, g, b } }) => {
  205. this.unified_attrib.assist_color = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
  206. });
  207. },
  208. handleClose() {
  209. this.$emit('update:visible', false);
  210. },
  211. confirm() {
  212. this.$emit('update:visible', false);
  213. this.$emit('fullTextSettings', this.unified_attrib);
  214. },
  215. applyToSelectedComponents() {
  216. this.$emit('update:visible', false);
  217. this.$emit('applyToSelectedComponents', this.unified_attrib);
  218. },
  219. /**
  220. * 应用单个属性到选中组件
  221. * @param {String} attr - 属性名
  222. */
  223. applySingleAttrToSelectedComponents(attr) {
  224. this.$emit('update:visible', false);
  225. this.$emit('applySingleAttrToSelectedComponents', { attr, value: this.unified_attrib[attr] });
  226. },
  227. /**
  228. * 应用单个属性到所有组件
  229. * @param {String} attr - 属性名
  230. */
  231. applySingleAttrToAllComponents(attr) {
  232. this.$emit('update:visible', false);
  233. this.$emit('applySingleAttrToAllComponents', { attr, value: this.unified_attrib[attr] });
  234. },
  235. },
  236. };
  237. </script>
  238. <style lang="scss" scoped>
  239. .full-text-settings {
  240. padding: 0;
  241. .el-form {
  242. .color-group {
  243. display: flex;
  244. column-gap: 6px;
  245. align-items: center;
  246. span {
  247. white-space: nowrap;
  248. }
  249. }
  250. :deep .el-form-item__content {
  251. display: flex;
  252. align-items: center;
  253. > :first-child {
  254. flex: 1;
  255. }
  256. }
  257. .row-button {
  258. margin-left: 12px;
  259. }
  260. }
  261. }
  262. </style>