Bladeren bron

feat(fatloss-miniprogram): init project scaffold

Sisyphus 3 dagen geleden
bovenliggende
commit
777d2b21c3

+ 42 - 0
xiaofat-miniprogram/App.vue

@@ -0,0 +1,42 @@
+<script>
+export default {
+  onLaunch: function() {
+    var cachedOpenid = uni.getStorageSync('openid')
+    if (!cachedOpenid) {
+      uni.login({
+        provider: 'weixin',
+        success: function(loginRes) {
+          if (loginRes && loginRes.code) {
+            uni.request({
+              url: 'https://cfc.etotem.com.cn/api/auth/silent-login',
+              method: 'POST',
+              data: { code: loginRes.code },
+              header: { 'Content-Type': 'application/json' },
+              success: function(res) {
+                if (res.data && res.data.code === 200 && res.data.data) {
+                  var d = res.data.data
+                  uni.setStorageSync('token', d.token)
+                  uni.setStorageSync('openid', d.openid)
+                  uni.setStorageSync('userId', d.userId)
+                  uni.setStorageSync('userInfo', {
+                    nickname: d.nickname,
+                    userId: d.userId,
+                    familyId: d.familyId
+                  })
+                }
+              },
+              fail: function() {
+                uni.showToast({ title: '网络请求失败', icon: 'none' })
+              }
+            })
+          }
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style>
+page { background-color: #F8F8F8; font-size: 28rpx; color: #333; }
+</style>

+ 22 - 0
xiaofat-miniprogram/config.js

@@ -0,0 +1,22 @@
+let API_BASE_URL = 'https://cfc.etotem.com.cn'
+
+try {
+  const accountInfo = uni.getAccountInfoSync()
+  const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
+  if (env) {
+    switch (env) {
+      case 'develop':
+      case 'trial':
+      case 'release':
+        API_BASE_URL = 'https://cfc.etotem.com.cn'
+        break
+    }
+  }
+} catch (e) {}
+
+export default {
+  API_BASE_URL,
+  api(path) {
+    return API_BASE_URL + path
+  }
+}

+ 14 - 0
xiaofat-miniprogram/main.js

@@ -0,0 +1,14 @@
+import Vue from 'vue'
+import App from './App'
+import store from './store'
+
+Vue.config.productionTip = false
+Vue.prototype.$store = store
+
+App.mpType = 'app'
+
+const app = new Vue({
+  ...App,
+  store
+})
+app.$mount()

+ 20 - 0
xiaofat-miniprogram/manifest.json

@@ -0,0 +1,20 @@
+{
+  "name": "减脂营",
+  "appid": "__UNI__FATLOSS",
+  "description": "科学减脂,从记录开始",
+  "versionName": "1.0.0",
+  "versionCode": "100",
+  "transformPx": false,
+  "mp-weixin": {
+    "appid": "__UNI__FATLOSS",
+    "setting": {
+      "urlCheck": false,
+      "es6": true,
+      "postcss": true,
+      "minified": true
+    },
+    "usingComponents": true,
+    "permission": {}
+  },
+  "vueVersion": "2"
+}

+ 7 - 0
xiaofat-miniprogram/package.json

@@ -0,0 +1,7 @@
+module.exports = {
+  name: 'xiaofat-miniprogram',
+  version: '1.0.0',
+  uni: {
+    description: '减脂专题小程序'
+  }
+}

+ 77 - 0
xiaofat-miniprogram/pages.json

@@ -0,0 +1,77 @@
+{
+  "pages": [
+    {
+      "path": "pages/index/index",
+      "style": { "navigationBarTitleText": "减脂营" }
+    },
+    {
+      "path": "pages/weight/index",
+      "style": { "navigationBarTitleText": "体重" }
+    },
+    {
+      "path": "pages/diet/index",
+      "style": { "navigationBarTitleText": "饮食" }
+    },
+    {
+      "path": "pages/exercise/index",
+      "style": { "navigationBarTitleText": "运动" }
+    },
+    {
+      "path": "pages/ai-coach/index",
+      "style": { "navigationBarTitleText": "AI教练" }
+    }
+  ],
+  "subPackages": [
+    {
+      "root": "pages/weight",
+      "pages": [
+        { "path": "create", "style": { "navigationBarTitleText": "记录体重" } },
+        { "path": "chart", "style": { "navigationBarTitleText": "体重趋势" } }
+      ]
+    },
+    {
+      "root": "pages/diet",
+      "pages": [
+        { "path": "create", "style": { "navigationBarTitleText": "记录饮食" } },
+        { "path": "food-query", "style": { "navigationBarTitleText": "食物热量查询" } }
+      ]
+    },
+    {
+      "root": "pages/exercise",
+      "pages": [
+        { "path": "create", "style": { "navigationBarTitleText": "记录运动" } }
+      ]
+    },
+    {
+      "root": "pages/profile",
+      "pages": [
+        { "path": "index", "style": { "navigationBarTitleText": "我的" } }
+      ]
+    }
+  ],
+  "globalStyle": {
+    "navigationBarTextStyle": "black",
+    "navigationBarTitleText": "减脂营",
+    "navigationBarBackgroundColor": "#FFFFFF",
+    "backgroundColor": "#F8F8F8"
+  },
+  "tabBar": {
+    "color": "#7A7E83",
+    "selectedColor": "#F97316",
+    "borderStyle": "black",
+    "backgroundColor": "#FFFFFF",
+    "list": [
+      { "pagePath": "pages/index/index", "text": "首页" },
+      { "pagePath": "pages/weight/index", "text": "体重" },
+      { "pagePath": "pages/diet/index", "text": "饮食" },
+      { "pagePath": "pages/exercise/index", "text": "运动" },
+      { "pagePath": "pages/ai-coach/index", "text": "AI教练" }
+    ]
+  },
+  "easycom": {
+    "autoscan": true,
+    "custom": {
+      "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
+    }
+  }
+}

+ 62 - 0
xiaofat-miniprogram/store/index.js

@@ -0,0 +1,62 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+
+Vue.use(Vuex)
+
+const store = new Vuex.Store({
+  state: {
+    token: '',
+    userId: null,
+    memberId: null,
+    nickname: '',
+    familyId: null,
+    openid: '',
+    isLoggedIn: false
+  },
+  mutations: {
+    setToken(state, token) {
+      state.token = token
+      uni.setStorageSync('token', token)
+    },
+    setUserInfo(state, info) {
+      state.userId = info.userId
+      state.memberId = info.memberId
+      state.nickname = info.nickname
+      state.familyId = info.familyId
+      state.openid = info.openid
+      state.isLoggedIn = !!info.userId
+    },
+    logout(state) {
+      state.token = ''
+      state.userId = null
+      state.memberId = null
+      state.nickname = ''
+      state.familyId = null
+      state.openid = ''
+      state.isLoggedIn = false
+      uni.removeStorageSync('token')
+      uni.removeStorageSync('openid')
+      uni.removeStorageSync('userId')
+    }
+  },
+  actions: {
+    initFromStorage({ commit }) {
+      var token = uni.getStorageSync('token')
+      var openid = uni.getStorageSync('openid')
+      var userId = uni.getStorageSync('userId')
+      if (token) commit('setToken', token)
+      if (userId) {
+        var userInfo = uni.getStorageSync('userInfo') || {}
+        commit('setUserInfo', {
+          userId: userId,
+          memberId: userInfo.memberId,
+          nickname: userInfo.nickname,
+          familyId: userInfo.familyId,
+          openid: openid
+        })
+      }
+    }
+  }
+})
+
+export default store