app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const state = {
  2. model: '',
  3. safeArea: true,
  4. isIphoneX: '',
  5. systemInfo: {},
  6. isIphone: true,
  7. }
  8. const mutations = {
  9. SET_SYSTEM_INFO: (state, info) => {
  10. state.systemInfo = info
  11. },
  12. SET_MODEL: (state, model) => {
  13. console.log('model', model)
  14. state.model = model
  15. },
  16. SET_SAFE_AREA: (state, safeArea) => {
  17. console.log('safeArea', safeArea)
  18. state.safeArea = safeArea
  19. },
  20. SET_CHANGE_VAR: (state, isIphoneX) => {
  21. state.isIphoneX = isIphoneX
  22. },
  23. SET_IS_IPHONE: (state, isIphone) => {
  24. state.isIphone = isIphone
  25. },
  26. }
  27. const actions = {
  28. initDevice({ commit }) {
  29. const systemInfo = uni.getSystemInfoSync()
  30. commit('SET_SYSTEM_INFO', systemInfo)
  31. const model = systemInfo.model.toLowerCase().trim()
  32. commit('SET_MODEL', model)
  33. const reg = /^iphone\s?[4|5|6|7|8]{1}/gi
  34. if (reg.test(model) || model.indexOf('iphone') === -1) {
  35. commit('SET_SAFE_AREA', false)
  36. }
  37. },
  38. setVariableFun: function(context, vData) {
  39. context.commit('SET_CHANGE_VAR', vData)
  40. },
  41. setIsIphoneFun: function(context, vData) {
  42. context.commit('SET_IS_IPHONE', vData)
  43. },
  44. }
  45. export default {
  46. namespaced: true,
  47. state,
  48. mutations,
  49. actions
  50. }