app.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { Provider } from '@tarojs/redux'
  3. import Index from './pages/index'
  4. import configStore from './store'
  5. import 'taro-ui/dist/style/index.scss'
  6. import './app.scss'
  7. import api from './api'
  8. Taro.api = api
  9. import * as tools from './utils/tool'
  10. Taro.$msg = tools.msgBase
  11. Taro.$CR = tools.configRight
  12. Taro.$msgConfirm = tools.confirmMsgFn
  13. // 如果需要在 h5 环境中开启 React Devtools
  14. // 取消以下注释:
  15. // if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5') {
  16. // require('nerv-devtools')
  17. // }
  18. const store = configStore()
  19. class App extends Component {
  20. config = {
  21. pages: [
  22. 'pages/index/index',
  23. ],
  24. subPackages: [
  25. {
  26. root: 'pagesHouse/',
  27. pages: [
  28. 'index',
  29. 'list',
  30. 'indexDtl',
  31. 'indexDtlMore',
  32. 'indexDtlAround',
  33. 'indexDtlMap',
  34. 'produceType',
  35. 'photo',
  36. 'news',
  37. 'follow',
  38. 'history',
  39. 'search',
  40. 'pkList',
  41. 'pkDtl',
  42. 'pkAdd',
  43. 'price',
  44. 'discountGroup',
  45. 'roomPrice',
  46. 'roomPriceImg',
  47. 'roomPriceList',
  48. ]
  49. },
  50. {
  51. root: 'pagesMore/',
  52. pages: [
  53. 'news/index',
  54. 'news/list',
  55. 'news/indexDtl',
  56. 'news/tpDtl',
  57. 'center/index',
  58. 'center/group',
  59. 'center/queryBuyHouse',
  60. 'center/feedback',
  61. 'center/loanCalc',
  62. 'center/webViews',
  63. 'center/message',
  64. 'center/coupon',
  65. 'center/sxf',
  66. 'comment/add',
  67. 'comment/list',
  68. 'comment/dtl',
  69. // 'qa/list',
  70. // 'qa/add',
  71. // 'qa/dtl',
  72. ]
  73. },
  74. {
  75. root: 'pagesPlan/',
  76. pages: [
  77. 'apply'
  78. ]
  79. },
  80. {
  81. root: 'pagesSchool/',
  82. pages: [
  83. 'index',
  84. 'indexDtl',
  85. 'houseList',
  86. 'class',
  87. 'theme',
  88. 'area',
  89. ]
  90. },
  91. {
  92. root: 'pagesQa/',
  93. pages: [
  94. 'index',
  95. 'add',
  96. 'dtl',
  97. 'dtlSub',
  98. ]
  99. },
  100. ],
  101. window: {
  102. backgroundTextStyle: 'light',
  103. navigationBarBackgroundColor: '#fff',
  104. navigationBarTitleText: 'WeChat',
  105. navigationBarTextStyle: 'black'
  106. },
  107. plugins: {
  108. "chooseLocation": {
  109. "version": "1.0.6",
  110. "provider": "wx76a9a06e5b4e693e"
  111. }
  112. },
  113. permission: {
  114. "scope.userLocation": {
  115. "desc": "你的位置信息将用于小程序定位"
  116. }
  117. }
  118. }
  119. componentWillMount () {
  120. // Taro.loadFontFace({
  121. // global: true,
  122. // family: 'pf',
  123. // source: 'url("http://h5.honglounews.com/PF.TTF")',
  124. // })
  125. Taro.api.base.admdicttree().then(res =>{
  126. const cObj = res || {}
  127. let newDict = {}
  128. for (let k in cObj) {
  129. const cArr = cObj[k].map(item => {
  130. return {
  131. ...item,
  132. key: item.dict_label,
  133. val: item.dict_value
  134. }
  135. })
  136. newDict[k] = cArr
  137. }
  138. Taro.$dictData = newDict
  139. Taro.setStorageSync('dictData', newDict)
  140. })
  141. Taro.removeStorageSync('APP_indexOpen')
  142. Taro.setStorageSync('APP_newsDot', 'yes')
  143. let that = this
  144. let uiObj = Taro.getStorageSync('APP_userInfo')
  145. if (uiObj && uiObj.phone === '15625261123') {
  146. return
  147. }
  148. Taro.login({
  149. success: function (res) {
  150. if (res.code) {
  151. Taro.api.base.apiwxautologin({code: res.code}).then(data => {
  152. if (data.token === 'error') {
  153. Taro.removeStorageSync('APP_token')
  154. } else {
  155. const userInfo = {
  156. nickName: data.nickname,
  157. avatarUrl: data.avatar,
  158. phone: data.phone,
  159. }
  160. Taro.setStorageSync('APP_userInfo', userInfo)
  161. that.setState({
  162. userInfo
  163. })
  164. Taro.setStorageSync('APP_token', data.token)
  165. }
  166. })
  167. }
  168. }
  169. })
  170. }
  171. componentDidMount () {}
  172. componentDidShow () {}
  173. componentDidHide () {}
  174. componentDidCatchError () {}
  175. // 在 App 类中的 render() 函数没有实际作用
  176. // 请勿修改此函数
  177. render () {
  178. return (
  179. <Provider store={store}>
  180. <Index />
  181. </Provider>
  182. )
  183. }
  184. }
  185. Taro.render(<App />, document.getElementById('app'))