BookUnifiedAttr.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <el-dialog
  3. title="全文设置"
  4. :visible="visible"
  5. width="600px"
  6. :close-on-click-modal="false"
  7. class="book-unified-attr"
  8. @close="dialogClose"
  9. >
  10. <div class="setting-top">
  11. <div class="form">
  12. <el-form ref="form" :model="unified_attrib" label-width="80px" size="small">
  13. <el-form-item label="主题色">
  14. <div class="color-group">
  15. <el-color-picker v-model="unified_attrib.topic_color" />
  16. <span>辅助色</span>
  17. <el-color-picker v-model="unified_attrib.assist_color" />
  18. </div>
  19. </el-form-item>
  20. <el-form-item label="字体">
  21. <el-select v-model="unified_attrib.font" placeholder="请选择字体">
  22. <el-option label="楷体" value="楷体,微软雅黑" />
  23. <el-option label="黑体" value="黑体,微软雅黑" />
  24. <el-option label="宋体" value="宋体,微软雅黑" />
  25. <el-option label="Arial" value="Arial,Helvetica,sans-serif" />
  26. <el-option label="Times New Roman" value="Times New Roman,times,serif" />
  27. <el-option label="拼音" value="League" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="字号">
  31. <el-select v-model="unified_attrib.font_size" placeholder="请选择字号">
  32. <el-option v-for="size in fontSizeList" :key="size" :label="size" :value="size" />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="拼音字号">
  36. <el-select v-model="unified_attrib.pinyin_size" placeholder="请选择拼音字号">
  37. <el-option v-for="size in fontSizeList" :key="size" :label="size" :value="size" />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="行距">
  41. <el-input-number v-model="unified_attrib.line_height" :min="0" :max="20" :step="0.1" />
  42. </el-form-item>
  43. <el-form-item label="文字颜色">
  44. <el-color-picker v-model="unified_attrib.text_color" />
  45. </el-form-item>
  46. <el-form-item label="对齐方式">
  47. <el-select v-model="unified_attrib.align" placeholder="请选择对齐方式">
  48. <el-option label="左对齐" value="LEFT" />
  49. <el-option label="居中" value="MIDDLE" />
  50. <el-option label="右对齐" value="RIGHT" />
  51. </el-select>
  52. </el-form-item>
  53. </el-form>
  54. </div>
  55. <div class="tips" @click="applyBookUnifiedAttr">
  56. <p>重置当前教材所有内容</p>
  57. <p style="color: #f00">(不包含富文本的现有文字属性)</p>
  58. </div>
  59. </div>
  60. <div class="setting-bottom">
  61. <span>拼音</span>
  62. <el-switch v-model="unified_attrib.view_pinyin" active-value="true" inactive-value="false" />
  63. <span>拼音位置</span>
  64. <el-radio-group v-model="unified_attrib.pinyin_position" :disabled="!isEnable(unified_attrib.view_pinyin)">
  65. <el-radio v-for="{ value, label } in pinyinPositionList" :key="value" :label="value">
  66. {{ label }}
  67. </el-radio>
  68. </el-radio-group>
  69. </div>
  70. <div slot="footer" class="dialog-footer">
  71. <el-button @click="dialogClose">取 消</el-button>
  72. <el-button type="primary" @click="saveBookUnifiedAttr">确定</el-button>
  73. </div>
  74. </el-dialog>
  75. </template>
  76. <script>
  77. import { pinyinPositionList, isEnable } from '@/views/book/courseware/data/common';
  78. import { GetBookUnifiedAttrib, ApplyBookUnifiedAttrib, SaveBookUnifiedAttrib } from '@/api/book';
  79. import { unified_attrib } from '@/common/data';
  80. export default {
  81. name: 'BookUnifiedAttrPage',
  82. props: {
  83. visible: {
  84. type: Boolean,
  85. required: true,
  86. },
  87. bookId: {
  88. type: String,
  89. required: true,
  90. },
  91. },
  92. data() {
  93. return {
  94. unified_attrib,
  95. fontSizeList: [
  96. '8pt',
  97. '10pt',
  98. '12pt',
  99. '14pt',
  100. '16pt',
  101. '18pt',
  102. '20pt',
  103. '22pt',
  104. '24pt',
  105. '26pt',
  106. '28pt',
  107. '30pt',
  108. '32pt',
  109. '34pt',
  110. '36pt',
  111. ],
  112. pinyinPositionList,
  113. isEnable,
  114. };
  115. },
  116. watch: {
  117. visible(newVal) {
  118. if (newVal) {
  119. this.getBookUnifiedAttr();
  120. }
  121. },
  122. },
  123. methods: {
  124. getBookUnifiedAttr() {
  125. GetBookUnifiedAttrib({ book_id: this.bookId }).then(({ content }) => {
  126. if (content) {
  127. this.unified_attrib = JSON.parse(content);
  128. }
  129. });
  130. },
  131. applyBookUnifiedAttr() {
  132. let loading = this.$loading({ fullscreen: true, text: '正在应用,请稍后...' });
  133. ApplyBookUnifiedAttrib({
  134. book_id: this.bookId,
  135. content: JSON.stringify(this.unified_attrib),
  136. })
  137. .then(() => {
  138. this.$message.success('应用成功');
  139. this.dialogClose();
  140. })
  141. .finally(() => {
  142. loading.close();
  143. });
  144. },
  145. saveBookUnifiedAttr() {
  146. SaveBookUnifiedAttrib({
  147. book_id: this.bookId,
  148. content: JSON.stringify(this.unified_attrib),
  149. }).then(() => {
  150. this.$message.success('保存成功');
  151. this.dialogClose();
  152. });
  153. },
  154. dialogClose() {
  155. this.$emit('update:visible', false);
  156. this.$emit('close');
  157. },
  158. },
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .book-unified-attr {
  163. .setting-top {
  164. display: flex;
  165. .form {
  166. flex: 1;
  167. .el-input-number {
  168. width: calc(100% - 42px);
  169. }
  170. .color-group {
  171. display: flex;
  172. column-gap: 10px;
  173. align-items: center;
  174. span {
  175. white-space: nowrap;
  176. }
  177. }
  178. }
  179. .tips {
  180. display: flex;
  181. flex-direction: column;
  182. align-items: center;
  183. justify-content: center;
  184. width: 240px;
  185. font-size: 12px;
  186. line-height: 1.5;
  187. text-align: center;
  188. cursor: pointer;
  189. background-color: rgba(22, 93, 255, 8%);
  190. border-radius: 8px;
  191. }
  192. }
  193. .setting-bottom {
  194. display: flex;
  195. column-gap: 10px;
  196. align-items: center;
  197. padding-top: 20px;
  198. margin-top: 20px;
  199. border-top: $border;
  200. }
  201. }
  202. </style>