tm-vuetify.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. let moduleTrue = {};
  5. // 为了兼容如果用户,不按规范创建,或者不使用vuex时就可略过导入用户的模块。
  6. try {
  7. const modulesList = require.context('@/store', true, /\.js$/);
  8. if (typeof modulesList === 'function' && typeof modulesList !== 'undefined') {
  9. // 加载modules目录下所有文件(分模块)
  10. const modules = modulesList.keys().reduce((modules, modulePath) => {
  11. const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  12. const value = modulesList(modulePath)
  13. modules[moduleName] = { namespaced: true, ...value.default }
  14. return modules
  15. }, {});
  16. moduleTrue = modules;
  17. }
  18. } catch (e) {
  19. //TODO handle the exception
  20. // console.warn('tmui提醒:用户未使用vuex')
  21. console.error('如果未使用vuex,不用理会,如果使用了vuex报错请检错误信息:',e);
  22. }
  23. let pdefault_cookies_color = uni.getStorageSync('setTmVuetifyColor')
  24. let pdefault_cookies_black = uni.getStorageSync('setTmVuetifyBlack')
  25. const store = new Vuex.Store({
  26. modules: {
  27. ...moduleTrue
  28. },
  29. state: {
  30. tmVuetify: {
  31. color: typeof pdefault_cookies_color === 'string' ? pdefault_cookies_color : '',
  32. black: typeof pdefault_cookies_black === 'boolean' ? pdefault_cookies_black : false,
  33. tmVueTifly_pages: '',
  34. tmVueTifly_pagesIndex: '',
  35. //这里是微信小程序和微信H5的配置资料。
  36. wxshareConfig_miniMp: {
  37. title: '', // 分享标题
  38. desc: '', // 描述
  39. imageUrl: '', // 分享图片
  40. path: '', // 分享路径
  41. copyLink: '', // 复制链接
  42. query: {}, // 分享参数
  43. }
  44. },
  45. },
  46. getters: {
  47. // $tm:state=>{
  48. // return $tm;
  49. // }
  50. },
  51. mutations: {
  52. setTmVuetifyColor(state, color) {
  53. Vue.set(state.tmVuetify, 'color', color)
  54. },
  55. setPageNow(state, url) {
  56. Vue.set(state.tmVuetify, 'tmVueTifly_pages', url);
  57. },
  58. setPageNowIndex(state, index) {
  59. Vue.set(state.tmVuetify, 'tmVueTifly_pagesIndex', index);
  60. },
  61. setTmVuetifyBlack(state, black) {
  62. Vue.set(state.tmVuetify, 'black', black)
  63. if (black === true) {
  64. uni.setTabBarStyle({
  65. backgroundColor: "#1B1B1B"
  66. })
  67. } else {
  68. uni.setTabBarStyle({
  69. backgroundColor: "#FFFFFF"
  70. })
  71. }
  72. },
  73. setWxShare(state, cfg) {
  74. let pcf = cfg||{};
  75. if(typeof pcf !=='object' || Array.isArray(cfg)) pcf = {};
  76. Vue.set(state.tmVuetify, 'wxshareConfig_miniMp', { ...state.tmVuetify.wxshareConfig_miniMp,...pcf});
  77. }
  78. }
  79. })
  80. export default store;