index.js.主题设置 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. //node_modules\@ant-design-vue\pro-layout\es\components\SettingDrawer
  2. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  3. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4. import './index.less';
  5. import omit from 'omit.js';
  6. import PropTypes from 'ant-design-vue/es/_util/vue-types';
  7. import 'ant-design-vue/es/divider/style';
  8. import Divider from 'ant-design-vue/es/divider';
  9. import 'ant-design-vue/es/drawer/style';
  10. import Drawer from 'ant-design-vue/es/drawer';
  11. import 'ant-design-vue/es/list/style';
  12. import List from 'ant-design-vue/es/list';
  13. import 'ant-design-vue/es/switch/style';
  14. import Switch from 'ant-design-vue/es/switch';
  15. import 'ant-design-vue/es/button/style';
  16. import Button from 'ant-design-vue/es/button';
  17. import 'ant-design-vue/es/icon/style';
  18. import Icon from 'ant-design-vue/es/icon';
  19. import 'ant-design-vue/es/alert/style';
  20. import Alert from 'ant-design-vue/es/alert';
  21. import antPortal from 'ant-design-vue/es/_util/portalDirective';
  22. import 'ant-design-vue/es/message/style';
  23. import message from 'ant-design-vue/es/message';
  24. import BlockCheckbox from './BlockCheckbox';
  25. import ThemeColor from './ThemeColor';
  26. import LayoutSetting, { renderLayoutSettingItem } from './LayoutChange';
  27. import { updateTheme, updateColorWeak } from '../../utils/dynamicTheme';
  28. import { contentWidthCheck, genStringToTheme } from '../../utils/util';
  29. import CopyToClipboard from 'vue-copy-to-clipboard';
  30. var baseClassName = 'ant-pro-setting-drawer';
  31. var BodyProps = {
  32. title: PropTypes.string.def('')
  33. };
  34. var Body = {
  35. props: BodyProps,
  36. render: function render(h) {
  37. var title = this.title;
  38. return h("div", {
  39. style: {
  40. marginBottom: 24
  41. }
  42. }, [h("h3", {
  43. "class": "".concat(baseClassName, "-title")
  44. }, [title]), this.$slots["default"]]);
  45. }
  46. };
  47. var defaultI18nRender = function defaultI18nRender(t) {
  48. return t;
  49. };
  50. var getThemeList = function getThemeList(i18nRender) {
  51. var list = window.umi_plugin_ant_themeVar || [];
  52. var themeList = [{
  53. key: 'light',
  54. url: 'https://gw.alipayobjects.com/zos/antfincdn/NQ%24zoisaD2/jpRkZQMyYRryryPNtyIC.svg',
  55. title: i18nRender('app.setting.pagestyle.light')
  56. }, {
  57. key: 'dark',
  58. url: 'https://gw.alipayobjects.com/zos/antfincdn/XwFOFbLkSM/LCkqqYNmvBEbokSDscrm.svg',
  59. title: i18nRender('app.setting.pagestyle.dark')
  60. }];
  61. var darkColorList = [{
  62. key: '#1890ff',
  63. color: '#1890ff',
  64. theme: 'dark'
  65. }];
  66. var lightColorList = [{
  67. key: '#1890ff',
  68. color: '#1890ff',
  69. theme: 'dark'
  70. }];
  71. if (list.find(function (item) {
  72. return item.theme === 'dark';
  73. })) {
  74. themeList.push({
  75. // disable click
  76. disable: true,
  77. key: 'realDark',
  78. url: 'https://gw.alipayobjects.com/zos/antfincdn/hmKaLQvmY2/LCkqqYNmvBEbokSDscrm.svg',
  79. title: i18nRender('app.setting.pagestyle.realdark')
  80. });
  81. } // insert theme color List
  82. list.forEach(function (item) {
  83. var color = (item.modifyVars || {})['@primary-color'];
  84. if (item.theme === 'dark' && color) {
  85. darkColorList.push(_objectSpread({
  86. color: color
  87. }, item));
  88. }
  89. if (!item.theme || item.theme === 'light') {
  90. lightColorList.push(_objectSpread({
  91. color: color
  92. }, item));
  93. }
  94. });
  95. return {
  96. colorList: {
  97. dark: darkColorList,
  98. light: lightColorList
  99. },
  100. themeList: themeList
  101. };
  102. };
  103. var handleChangeSetting = function handleChangeSetting(key, value, hideMessageLoading) {
  104. if (key === 'primaryColor') {
  105. // 更新主色调
  106. updateTheme(value);
  107. }
  108. if (key === 'colorWeak') {
  109. updateColorWeak(value);
  110. }
  111. };
  112. var genCopySettingJson = function genCopySettingJson(settings) {
  113. return JSON.stringify(omit(_objectSpread({}, settings, {
  114. primaryColor: genStringToTheme(settings.primaryColor)
  115. }), ['colorWeak']), null, 2);
  116. };
  117. export var settings = {
  118. theme: PropTypes.oneOf(['dark', 'light', 'realDark']),
  119. primaryColor: PropTypes.string,
  120. layout: PropTypes.oneOf(['sidemenu', 'topmenu']),
  121. colorWeak: PropTypes.bool,
  122. contentWidth: PropTypes.oneOf(['Fluid', 'Fixed']).def('Fluid'),
  123. // 替换兼容 PropTypes.oneOf(['Fluid', 'Fixed']).def('Fluid')
  124. // contentWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]).def('Fluid'),
  125. fixedHeader: PropTypes.bool,
  126. fixSiderbar: PropTypes.bool,
  127. hideHintAlert: PropTypes.bool.def(false),
  128. hideCopyButton: PropTypes.bool.def(false)
  129. };
  130. export var SettingDrawerProps = {
  131. getContainer: PropTypes.func,
  132. settings: PropTypes.objectOf(settings),
  133. i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false)
  134. };
  135. var SettingDrawer = {
  136. name: 'SettingDrawer',
  137. props: SettingDrawerProps,
  138. inject: ['locale'],
  139. data: function data() {
  140. return {
  141. show: false
  142. };
  143. },
  144. render: function render(h) {
  145. var _this = this;
  146. var setShow = this.setShow,
  147. getContainer = this.getContainer,
  148. settings = this.settings;
  149. var _settings$theme = settings.theme,
  150. theme = _settings$theme === void 0 ? 'dark' : _settings$theme,
  151. _settings$primaryColo = settings.primaryColor,
  152. primaryColor = _settings$primaryColo === void 0 ? 'daybreak' : _settings$primaryColo,
  153. _settings$layout = settings.layout,
  154. layout = _settings$layout === void 0 ? 'sidemenu' : _settings$layout,
  155. _settings$fixedHeader = settings.fixedHeader,
  156. fixedHeader = _settings$fixedHeader === void 0 ? false : _settings$fixedHeader,
  157. _settings$fixSiderbar = settings.fixSiderbar,
  158. fixSiderbar = _settings$fixSiderbar === void 0 ? false : _settings$fixSiderbar,
  159. contentWidth = settings.contentWidth,
  160. hideHintAlert = settings.hideHintAlert,
  161. hideCopyButton = settings.hideCopyButton,
  162. colorWeak = settings.colorWeak;
  163. var i18n = this.$props.i18nRender || this.locale || defaultI18nRender;
  164. var themeList = getThemeList(i18n);
  165. var isTopMenu = layout === 'topmenu';
  166. var iconStyle = {
  167. color: '#fff',
  168. fontSize: 20
  169. };
  170. var changeSetting = function changeSetting(type, value) {
  171. _this.$emit('change', {
  172. type: type,
  173. value: value
  174. });
  175. handleChangeSetting(type, value, false);
  176. };
  177. return h(Drawer, {
  178. attrs: {
  179. visible: this.show,
  180. width: 300,
  181. placement: "right",
  182. getContainer: getContainer
  183. /*handle={
  184. <div class="ant-pro-setting-drawer-handle" onClick={() => setShow(!this.show)}>
  185. {this.show
  186. ? (<Icon type="close" style={iconStyle} />)
  187. : (<Icon type="setting" style={iconStyle} />)
  188. }
  189. </div>
  190. }*/
  191. },
  192. on: {
  193. "close": function close() {
  194. return setShow(false);
  195. }
  196. },
  197. style: {
  198. zIndex: 999
  199. }
  200. }, [h("template", {
  201. slot: "handle"
  202. }, [h("div", {
  203. "class": "".concat(baseClassName, "-handle"),
  204. on: {
  205. "click": function click() {
  206. return setShow(!_this.show);
  207. }
  208. }
  209. }, [this.show ? h(Icon, {
  210. attrs: {
  211. type: "close"
  212. },
  213. style: iconStyle
  214. }) : h(Icon, {
  215. attrs: {
  216. type: "setting"
  217. },
  218. style: iconStyle
  219. })])]), h("div", {
  220. "class": "".concat(baseClassName, "-content")
  221. }, [h(Body, {
  222. attrs: {
  223. title: i18n('app.setting.pagestyle')
  224. }
  225. }, [h(BlockCheckbox, {
  226. attrs: {
  227. i18nRender: i18n,
  228. list: themeList.themeList,
  229. value: theme
  230. },
  231. on: {
  232. "change": function change(val) {
  233. changeSetting('theme', val);
  234. }
  235. }
  236. })]), h(ThemeColor, {
  237. attrs: {
  238. i18nRender: i18n,
  239. title: i18n('app.setting.themecolor'),
  240. value: primaryColor,
  241. colors: themeList.colorList[theme === 'realDark' ? 'dark' : 'light']
  242. },
  243. on: {
  244. "change": function change(color) {
  245. changeSetting('primaryColor', color, null);
  246. }
  247. }
  248. }), h(Divider), h(Body, {
  249. attrs: {
  250. title: i18n('app.setting.navigationmode')
  251. }
  252. }, [h(BlockCheckbox, {
  253. attrs: {
  254. i18nRender: i18n,
  255. value: layout
  256. },
  257. on: {
  258. "change": function change(value) {
  259. changeSetting('layout', value, null);
  260. }
  261. }
  262. })]), h(LayoutSetting, {
  263. attrs: {
  264. i18nRender: i18n,
  265. contentWidth: contentWidth,
  266. fixedHeader: fixedHeader,
  267. fixSiderbar: isTopMenu ? false : fixSiderbar,
  268. layout: layout
  269. },
  270. on: {
  271. "change": function change(_ref) {
  272. var type = _ref.type,
  273. value = _ref.value;
  274. changeSetting(type, value);
  275. }
  276. }
  277. }), h(Divider), h(Body, {
  278. attrs: {
  279. title: i18n('app.setting.othersettings')
  280. }
  281. }, [h(List, {
  282. attrs: {
  283. split: false,
  284. renderItem: function renderItem(item) {
  285. return renderLayoutSettingItem(h, item);
  286. },
  287. dataSource: [{
  288. title: i18n('app.setting.weakmode'),
  289. action: h(Switch, {
  290. attrs: {
  291. size: "small",
  292. checked: !!colorWeak
  293. },
  294. on: {
  295. "change": function change(checked) {
  296. return changeSetting('colorWeak', checked);
  297. }
  298. }
  299. })
  300. }]
  301. }
  302. })]), hideHintAlert && hideCopyButton ? null : h(Divider), hideHintAlert ? null : h(Alert, {
  303. attrs: {
  304. type: "warning",
  305. message: i18n('app.setting.production.hint'),
  306. icon: h(Icon, {
  307. attrs: {
  308. type: 'notification'
  309. }
  310. }),
  311. showIcon: false
  312. },
  313. style: {
  314. marginBottom: '16px',
  315. display:'none'
  316. }
  317. }), hideCopyButton ? null : h(CopyToClipboard, {
  318. attrs: {
  319. text: genCopySettingJson(settings)
  320. },
  321. on: {
  322. "copy": function copy() {
  323. localStorage.setItem('theme_save',JSON.stringify(settings));
  324. return message.success(i18n('app.setting.copyinfo'));
  325. }
  326. }
  327. }, [h(Button, {
  328. attrs: {
  329. block: true
  330. }
  331. }, [h(Icon, {
  332. attrs: {
  333. type: 'save'
  334. }
  335. }), i18n('app.setting.copy')])]), h("div", {
  336. "class": "".concat(baseClassName, "-content-footer")
  337. }, [this.$slots["default"]])])]);
  338. },
  339. methods: {
  340. setShow: function setShow(flag) {
  341. this.show = flag;
  342. }
  343. }
  344. };
  345. SettingDrawer.install = function (Vue) {
  346. Vue.use(antPortal);
  347. Vue.component(SettingDrawer.name, SettingDrawer);
  348. };
  349. export default SettingDrawer;