default.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { ISettingItem } from "../../../reducers/setting";
  2. export interface ISettingItemOption {
  3. label: string;
  4. value: string;
  5. }
  6. export interface ISetting {
  7. key: string;
  8. label: string;
  9. description: string;
  10. defaultValue: string | number | boolean;
  11. value?: string | number | boolean;
  12. widget?: "input" | "select" | "radio" | "radio-button";
  13. options?: ISettingItemOption[];
  14. max?: number;
  15. min?: number;
  16. }
  17. export const GetUserSetting = (
  18. key: string,
  19. curr?: ISettingItem[]
  20. ): string | number | boolean | undefined => {
  21. const currSetting = curr?.find((element) => element.key === key);
  22. if (typeof currSetting !== "undefined") {
  23. return currSetting.value;
  24. } else {
  25. const defaultSetting = SettingFind(key);
  26. if (typeof defaultSetting !== "undefined") {
  27. return defaultSetting.defaultValue;
  28. } else {
  29. return undefined;
  30. }
  31. }
  32. };
  33. export const SettingFind = (key: string): ISetting | undefined => {
  34. return defaultSetting.find((element) => element.key === key);
  35. };
  36. export const defaultSetting: ISetting[] = [
  37. {
  38. /**
  39. * 是否显示巴利原文
  40. */
  41. key: "setting.display.original",
  42. label: "setting.display.original.label",
  43. description: "setting.display.original.description",
  44. defaultValue: true,
  45. },
  46. {
  47. /**
  48. * 排版方向
  49. */
  50. key: "setting.layout.direction",
  51. label: "setting.layout.direction.label",
  52. description: "setting.layout.direction.description",
  53. defaultValue: "column",
  54. options: [
  55. {
  56. value: "column",
  57. label: "setting.layout.direction.col.label",
  58. },
  59. {
  60. value: "row",
  61. label: "setting.layout.direction.row.label",
  62. },
  63. ],
  64. widget: "radio-button",
  65. },
  66. {
  67. /**
  68. * 段落或者逐句对读
  69. */
  70. key: "setting.layout.paragraph",
  71. label: "setting.layout.paragraph.label",
  72. description: "setting.layout.paragraph.description",
  73. defaultValue: "sentence",
  74. options: [
  75. {
  76. value: "sentence",
  77. label: "setting.layout.paragraph.sentence.label",
  78. },
  79. {
  80. value: "paragraph",
  81. label: "setting.layout.paragraph.paragraph.label",
  82. },
  83. ],
  84. widget: "radio-button",
  85. },
  86. {
  87. /**
  88. * 第一巴利脚本
  89. */
  90. key: "setting.pali.script1",
  91. label: "setting.pali.script1.label",
  92. description: "setting.pali.script1.description",
  93. defaultValue: "roman",
  94. options: [
  95. {
  96. value: "roman",
  97. label: "setting.pali.script.rome.label",
  98. },
  99. {
  100. value: "roman_to_my",
  101. label: "setting.pali.script.my.label",
  102. },
  103. {
  104. value: "roman_to_si",
  105. label: "setting.pali.script.si.label",
  106. },
  107. {
  108. value: "roman_to_thai",
  109. label: "setting.pali.script.thai.label",
  110. },
  111. {
  112. value: "roman_to_taitham",
  113. label: "setting.pali.script.tai.label",
  114. },
  115. ],
  116. },
  117. {
  118. /**
  119. * 第二巴利脚本
  120. */
  121. key: "setting.pali.script2",
  122. label: "setting.pali.script2.label",
  123. description: "setting.pali.script2.description",
  124. defaultValue: "none",
  125. options: [
  126. {
  127. value: "none",
  128. label: "setting.pali.script.none.label",
  129. },
  130. {
  131. value: "roman",
  132. label: "setting.pali.script.rome.label",
  133. },
  134. {
  135. value: "roman_to_my",
  136. label: "setting.pali.script.my.label",
  137. },
  138. {
  139. value: "roman_to_si",
  140. label: "setting.pali.script.si.label",
  141. },
  142. ],
  143. },
  144. ];