app.js 774 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const state = {
  2. model: '',
  3. safeArea: true,
  4. systemInfo: {}
  5. }
  6. const mutations = {
  7. SET_SYSTEM_INFO: (state, info) => {
  8. state.systemInfo = info
  9. },
  10. SET_MODEL: (state, model) => {
  11. console.log('model', model)
  12. state.model = model
  13. },
  14. SET_SAFE_AREA: (state, safeArea) => {
  15. console.log('safeArea', safeArea)
  16. state.safeArea = safeArea
  17. },
  18. }
  19. const actions = {
  20. initDevice({ commit }) {
  21. const systemInfo = uni.getSystemInfoSync()
  22. commit('SET_SYSTEM_INFO', systemInfo)
  23. const model = systemInfo.model.toLowerCase().trim()
  24. commit('SET_MODEL', model)
  25. const reg = /^iphone\s?[4|5|6|7|8]{1}/gi
  26. if (reg.test(model) || model.indexOf('iphone') === -1) {
  27. commit('SET_SAFE_AREA', false)
  28. }
  29. }
  30. }
  31. export default {
  32. namespaced: true,
  33. state,
  34. mutations,
  35. actions
  36. }