Commit 3fc4f2db by huangzhi@yellow.com

init

parents
module.exports = {
// 提交流程
messages: {
type: '选择本次提交类型:',
customScope: '\n请输入修改范围:',
subject: '填写简短精炼的变更描述:\n',
body: '填写更详细的变更描述使用 "|" 换行:\n',
confirmCommit: '确认使用以上信息提交?(y/n)',
},
// 跳过步骤
skipQuestions: ['footer'],
// 可选类型
types: [
{ value: 'feat', name: 'feat: 添加新功能' },
{ value: 'fix', name: 'fix: 修复bug' },
{ value: 'docs', name: 'docs: 文档变更' },
{ value: 'style', name: 'style: 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑' },
{ value: 'refactor', name: 'refactor: 代码重构,没有加新功能或者修复bug' },
{ value: 'perf', name: 'perf: 优化相关,比如提升性能、体验' },
{ value: 'test', name: 'test: 测试' },
{ value: 'chore', name: 'chore: 改变构建流程、或者增加依赖库、工具等' },
{ value: 'revert', name: 'revert: 回滚到上一个版本' },
{ value: 'build', name: 'build: 部署版本' },
],
breaklineChar: '|',
subjectLimit: 100,
}
/node_modules/
/dist/
\ No newline at end of file
module.exports = {
// 此项是用来告诉eslint找当前配置文件不能往父级查找
root: true,
parserOptions: {
ecmaVersion: 12,
parser: 'babel-eslint',
sourceType: 'module',
allowImportExportEverywhere: true,
},
// 此项指定环境的全局变量,下面的配置指定为浏览器环境
env: {
browser: true,
},
plugins: [],
extends: ['vue', 'plugin:vue/recommended', 'plugin:prettier/recommended'],
// add your custom rules here
// 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致
// "off" -> 0 关闭规则
// "warn" -> 1 开启警告规则
// "error" -> 2 开启错误规则
rules: {
'space-before-function-paren': 0,
'comma-dangle': [1, 'always-multiline'],
'vue/singleline-html-element-content-newline': 0,
'vue/max-attributes-per-line': [
1,
{
singleline: {
max: 1,
},
multiline: {
max: 1,
},
},
],
camelcase: 0,
},
}
.DS_Store
node_modules/
unpackage/
dist/
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Lock files
yarn.lock
package-lock.json
# Editor directories and files
.hbuilderx
.project
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
/node_modules/
/dist/
\ No newline at end of file
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"htmlWhitespaceSensitivity": "ignore",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf",
"singleAttributePerLine": true
}
# uniapp-project
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run dev
```
### Compiles and minifies for production
```
npm run build
```
### eslint fix
```
npm run lint
```
### config husky
```
npm run prepare
```
## 目录结构
```
--public
--index.html // html模板
--src
--components // 全局组件
--pages // 页面
--plugins // 插件,axios等
--static // 静态资源
--store // 状态管理
--utils // 工具
App.vue // 根组件
config.js // 配置文件,根据环境导出不同的全局配置,hostPrefix、apiPrefix 等
main.js // 入口文件
pages.json // 小程序页面配置
```
### 组件库
项目接入了 `uView` 组件库,可以直接在 `template` 中使用组件,无需引入
## 请求
接入了 axios ,并进行了简单封装,通过 `this.$request` 发起请求。
请求拦截中会在 header 中带上 uid,accessToken。
响应拦截中有未登录处理,错误处理等。
```javascript
// Promise 写法
this.$request.get('xxx').then(res => {})
// async/await 写法
const res = await this.$request.post('xxx')
// 传参
const params = {}
this.$request.get('xxx', {
params
})
this.$request.post('xxx', params)
```
## 登录
提供了 `phone-login` 组件,用来调用手机号授权登录
登录接口需要在 store/modules/user.js 文件下的 login 方法中实现
## 埋点
目前前端的埋点库还不支持小程序,所以在 `utils/util.js` 里面封装了一个埋点请求,`sendTrackData`.
埋点封装的函数中的 `app_name` 参数需要根据实际项目定义填写进去。
埋点示例如下:
```javascript
setTrackData({
events: [
{
event_id: 'page_visit',
event_custom_properties: {
part: 'xxx',
position: '',
element: '',
},
},
],
})
```
## 代码风格
vscode 安装 ESLlint、Vetur、Prettier 这三个插件。
### Eslint
统一代码风格
### Vetur
让 vscode 识别 .vue 文件,实现语法高亮
### Prettier
格式化代码
vscode 设置里面勾选 Format On Save 可以在保存的时候格式化代码
## 提交规范
### 使用 commitizen 规范 commit 信息
全局安装 commitizen
```
npm install -g commitizen
```
安装后就可以使用 `git cz` 命令来提交代码了,cz 在命令行里面提供选项可以选择。
### 使用 husky 添加 git hook
npm install 时会自动执行 prepare 命令,执行该命令需要在项目根目录下有 .git 目录。如果没有执行该命令,手动执行下:
```
npm run prepare
```
增加 pre-commit hook:
```
// npm run lint 就是 commit 时要执行的命令,可根据实际命令调整
npx husky add .husky/pre-commit "npm run lint"
git add .husky/pre-commit
```
const webpack = require('webpack')
const plugins = []
if (process.env.UNI_OPT_TREESHAKINGNG) {
plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
}
if (
(
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) ||
(
process.env.UNI_PLATFORM === 'h5' &&
process.env.UNI_H5_BROWSER === 'builtin'
)
) {
const path = require('path')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const input = normalizePath(process.env.UNI_INPUT_DIR)
try {
plugins.push([
require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
{
file (file) {
file = normalizePath(file)
if (file.indexOf(input) === 0) {
return path.relative(input, file)
}
return false
}
}
])
} catch (e) { }
}
process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
process.UNI_LIBRARIES.forEach(libraryName => {
plugins.push([
'import',
{
'libraryName': libraryName,
'customName': (name) => {
return `${libraryName}/lib/${name}/${name}`
}
}
])
})
if (process.env.UNI_PLATFORM !== 'h5') {
plugins.push('@babel/plugin-transform-runtime')
}
const config = {
presets: [
[
'@vue/app',
{
modules: webpack.version[0] > 4 ? 'auto' : 'commonjs',
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
}
]
],
plugins
}
const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js'
if (process.env.NODE_ENV === 'production') {
config.overrides = [{
test: UNI_H5_TEST,
compact: true,
}]
} else {
config.ignore = [UNI_H5_TEST]
}
module.exports = config
module.exports = {
// 继承的规则
extends: ['@commitlint/config-conventional'],
// 定义规则类型
rules: {
// type 类型定义,表示 git 提交的 type 必须在以下类型范围内
'type-enum': [
2,
'always',
[
'feat', // 新功能 feature
'fix', // 修复 bug
'docs', // 项目文档或注释变更
'style', // 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑
'refactor', // 代码重构,没有加新功能或者修复bug
'perf', // 优化相关,比如提升性能、体验
'test', // 增加测试
'chore', // 改变构建流程、或者增加依赖库、工具等
'revert', // 回滚到上一个版本
'build', // 部署版本
],
],
// subject 大小写不做校验
'subject-case': [0],
},
}
{
"compilerOptions": {
"types": [
"@dcloudio/types",
"miniprogram-api-typings",
"mini-types"
]
}
}
{
"name": "group_course",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "npm run dev:h5",
"build": "npm run build:h5",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
"build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
"build:mp-360": "cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build",
"build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
"build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
"build:mp-jd": "cross-env NODE_ENV=production UNI_PLATFORM=mp-jd vue-cli-service uni-build",
"build:mp-kuaishou": "cross-env NODE_ENV=production UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build",
"build:mp-lark": "cross-env NODE_ENV=production UNI_PLATFORM=mp-lark vue-cli-service uni-build",
"build:mp-qq": "cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build",
"build:mp-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
"build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
"build:mp-xhs": "cross-env NODE_ENV=production UNI_PLATFORM=mp-xhs vue-cli-service uni-build",
"build:quickapp-native": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-native vue-cli-service uni-build",
"build:quickapp-webview": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview vue-cli-service uni-build",
"build:quickapp-webview-huawei": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build",
"build:quickapp-webview-union": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build",
"dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
"dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",
"dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
"dev:mp-360": "cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch",
"dev:mp-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
"dev:mp-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
"dev:mp-jd": "cross-env NODE_ENV=development UNI_PLATFORM=mp-jd vue-cli-service uni-build --watch",
"dev:mp-kuaishou": "cross-env NODE_ENV=development UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build --watch",
"dev:mp-lark": "cross-env NODE_ENV=development UNI_PLATFORM=mp-lark vue-cli-service uni-build --watch",
"dev:mp-qq": "cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch",
"dev:mp-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
"dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
"dev:mp-xhs": "cross-env NODE_ENV=development UNI_PLATFORM=mp-xhs vue-cli-service uni-build --watch",
"dev:quickapp-native": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-native vue-cli-service uni-build --watch",
"dev:quickapp-webview": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview vue-cli-service uni-build --watch",
"dev:quickapp-webview-huawei": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build --watch",
"dev:quickapp-webview-union": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build --watch",
"info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js",
"serve:quickapp-native": "node node_modules/@dcloudio/uni-quickapp-native/bin/serve.js",
"test:android": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i",
"test:h5": "cross-env UNI_PLATFORM=h5 jest -i",
"test:ios": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i",
"test:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu jest -i",
"test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i",
"lint": "eslint --ext .vue,.js --fix src",
"prepare": "husky install"
},
"dependencies": {
"@dcloudio/uni-app": "^2.0.2-3061520221228001",
"@dcloudio/uni-app-plus": "^2.0.2-3061520221228001",
"@dcloudio/uni-h5": "^2.0.2-3061520221228001",
"@dcloudio/uni-i18n": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-360": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-alipay": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-baidu": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-jd": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-kuaishou": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-lark": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-qq": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-toutiao": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-vue": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-weixin": "^2.0.2-3061520221228001",
"@dcloudio/uni-mp-xhs": "^2.0.2-3061520221228001",
"@dcloudio/uni-quickapp-native": "^2.0.2-3061520221228001",
"@dcloudio/uni-quickapp-webview": "^2.0.2-3061520221228001",
"@dcloudio/uni-stacktracey": "^2.0.2-3061520221228001",
"@dcloudio/uni-stat": "^2.0.2-3061520221228001",
"@vue/shared": "^3.0.0",
"axios": "^0.27.2",
"axios-adapter-uniapp": "^0.1.4",
"core-js": "^3.6.5",
"flyio": "^0.6.2",
"uview-ui": "^2.0.35",
"vue": "^2.6.11",
"vuex": "^3.2.0"
},
"devDependencies": {
"@commitlint/cli": "^16.3.0",
"@commitlint/config-conventional": "^16.2.4",
"@dcloudio/types": "^3.0.4",
"@dcloudio/uni-automator": "^2.0.2-3061520221228001",
"@dcloudio/uni-cli-i18n": "^2.0.2-3061520221228001",
"@dcloudio/uni-cli-shared": "^2.0.2-3061520221228001",
"@dcloudio/uni-helper-json": "*",
"@dcloudio/uni-migration": "^2.0.2-3061520221228001",
"@dcloudio/uni-template-compiler": "^2.0.2-3061520221228001",
"@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.2-3061520221228001",
"@dcloudio/vue-cli-plugin-uni": "^2.0.2-3061520221228001",
"@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.2-3061520221228001",
"@dcloudio/webpack-uni-mp-loader": "^2.0.2-3061520221228001",
"@dcloudio/webpack-uni-pages-loader": "^2.0.2-3061520221228001",
"@vue/cli-plugin-babel": "~4.5.19",
"@vue/cli-service": "~4.5.19",
"autoprefixer": "^8.6.5",
"babel-eslint": "^10.1.0",
"babel-plugin-import": "^1.11.0",
"cross-env": "^7.0.2",
"cz-customizable": "^7.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-vue": "^2.0.2",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.8.0",
"husky": "^7.0.4",
"jest": "^25.4.0",
"less": "^3.13.1",
"less-loader": "^5.0.0",
"mini-types": "*",
"miniprogram-api-typings": "*",
"postcss-comment": "^2.0.0",
"sass": "^1.57.1",
"sass-loader": "^8.0.2",
"vue-template-compiler": "^2.6.11"
},
"browserslist": [
"defaults",
"not ie < 8",
"last 2 versions",
"> 1%",
"Android >= 4.4",
"ios >= 9",
"last 3 iOS versions"
],
"uni-app": {
"scripts": {}
},
"config": {
"commitizen": {
"path": "./node_modules/cz-customizable"
}
}
}
const path = require('path')
const webpack = require('webpack')
const config = {
parser: require('postcss-comment'),
plugins: [
require('postcss-import')({
resolve(id, basedir, importOptions) {
if (id.startsWith('~@/')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
} else if (id.startsWith('@/')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
} else if (id.startsWith('/') && !id.startsWith('//')) {
return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
}
return id
},
}),
require('autoprefixer')({
remove: process.env.UNI_PLATFORM !== 'h5',
}),
require('@dcloudio/vue-cli-plugin-uni/packages/postcss'),
],
}
if (webpack.version[0] > 4) {
delete config.parser
}
module.exports = config
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
</head>
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
\ No newline at end of file
<script>
export default {
onLaunch: function () {
console.log('App Launch')
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},
}
</script>
<style lang="scss">
@import 'uview-ui/index.scss';
uni-page-body,
html,
body {
height: 100%;
}
</style>
<template>
<button
type="default"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
>
{{ text }}
</button>
</template>
<script>
export default {
name: 'PhoneLogin',
props: {
text: {
type: String,
default: '登录',
},
},
data() {
return {
loading: false,
}
},
async mounted() {
if (!this.$store.state.user.code) {
this.uniLogin()
} else {
// eslint-disable-next-line
uni.checkSession({
success: res => {
if (res.errMsg !== 'checkSession:ok') {
this.uniLogin()
}
},
})
}
},
methods: {
async getPhoneNumber({ detail: { errMsg, encryptedData, iv } }) {
if (errMsg === 'getPhoneNumber:ok') {
try {
this.loading = true
await this.$store.dispatch('user/login', {
encryptedData,
iv,
code: this.$store.state.user.code,
})
this.loading = false
this.$store.commit('user/setCode', '')
this.$emit('success')
} catch (e) {
console.log(e)
this.loading = false
}
} else {
// eslint-disable-next-line
uni.showToast({
title: '获取手机号失败',
duration: 3000,
})
}
},
uniLogin() {
return this.$store.dispatch('user/uniLogin')
},
},
}
</script>
<style lang="less"></style>
const isDevelopment = process.env.NODE_ENV === 'development'
let hostPrefix
let apiPrefix
if (isDevelopment) {
hostPrefix = 'https://testnewm.ydl.com'
apiPrefix = 'https://testapi.ydl.com'
} else {
hostPrefix = 'https://m.ydl.com'
apiPrefix = 'https://api.ydl.com'
}
module.exports = {
hostPrefix,
apiPrefix,
}
import Vue from 'vue'
import App from '@/App'
import store from '@/store'
import request from '@/plugins/request.js'
import uView from 'uview-ui'
Vue.config.productionTip = false
Vue.prototype.$store = store
Vue.prototype.$request = request
Vue.use(uView)
App.mpType = 'app'
const app = new Vue({
store,
...App,
})
app.$mount()
{
"name": "",
"appid": "",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"app-plus": { /* 5+App特有相关 */
"usingComponents": true,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
"modules": { /* 模块配置 */
},
"distribute": { /* 应用发布信息 */
"android": { /* android打包配置 */
"permissions": ["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
"ios": { /* ios打包配置 */
},
"sdkConfigs": { /* SDK配置 */
}
}
},
"quickapp": { /* 快应用特有相关 */
},
"mp-weixin": { /* 微信小程序特有相关 */
"appid": "wx1106c32a36d87d49",
"setting": {
"urlCheck": false
},
"usingComponents": true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"mp-qq" : {
"usingComponents" : true
}
}
{
"easycom": {
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
},
"pages": [
{
"path" : "pages/home/home",
"style" :
{
"navigationBarTitleText": "首页",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/my/my",
"style" :
{
"navigationBarTitleText": "我的",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "壹点灵心理咨询",
"navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#ffffff",
"backgroundTextStyle": "dark"
},
"tabBar": {
"color": "#76787C",
"selectedColor": "#55B5F3",
"iconWidth": "20px",
"spacing": "9px",
"list": [
{
"text": "首页",
"pagePath": "pages/home/home"
},
{
"text": "我的",
"pagePath": "pages/my/my"
}
]
}
}
<template>
<view class="content">
<image
class="logo"
src="/static/logo.png"
></image>
<view>
<text class="title">{{ title }}</text>
</view>
</view>
</template>
<script>
export default {
name: 'HomePage',
data() {
return {
title: 'Hello',
}
},
onLoad() {},
methods: {},
}
</script>
<style lang="less" scoped>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin: 200rpx auto 50rpx auto;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
<template>
<view>
<phone-login></phone-login>
</view>
</template>
<script>
import PhoneLogin from '@/components/phone-login.vue'
export default {
name: 'MyPage',
components: {
PhoneLogin,
},
data() {
return {}
},
methods: {},
}
</script>
<style></style>
/* eslint-disable no-undef */
import adapter from 'axios-adapter-uniapp'
import axios from 'axios'
import store from '@/store'
import { apiPrefix } from '@/config'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const baseURL = `${apiPrefix}/api`
const timeout = 20000
const service = axios.create({
baseURL,
timeout,
adapter,
})
// 请求拦截
service.interceptors.request.use(request => {
const accessToken = store.state.user.accessToken
if (accessToken) request.headers.accessToken = accessToken
const uid = store.state.user.uid
if (uid) request.headers.uid = uid
return request
})
// 响应拦截
service.interceptors.response.use(async res => {
// 配置了clearCode,清空store里面的code,获取最新的
if (res.config && res.config.clearCode) {
store.commit('user/setCode', '')
store.dispatch('user/uniLogin')
}
if (res.status === 200 && res.data) {
const code = +res.data.code
if (code === 200) {
return Promise.resolve(res.data.data)
} else if (code === 401) {
clearUserInfo()
uni.showToast({
title: '请先登录',
icon: 'none',
})
return Promise.reject(new Error('unlogin'))
} else if (
code === 40029 ||
code === 40163 ||
(res.data.errMsg || res.data.msg).includes('40029') ||
(res.data.errMsg || res.data.msg).includes('40163')
) {
clearUserInfo()
uni.showToast({
title: 'code已过期,请重新登录',
icon: 'none',
})
store.dispatch('user/uniLogin')
return Promise.reject(new Error('unlogin'))
} else {
if (res.data.errMsg || res.data.msg) {
// 错误统一处理
uni.showToast({
title: res.data.errMsg || res.data.msg,
icon: 'none',
})
}
return Promise.reject(res.data.errMsg || res.data.msg)
}
} else {
return Promise.reject(res)
}
})
const clearUserInfo = () => {
store.commit('user/setUserInfo', {})
store.commit('user/setCode', '')
store.commit('user/setUid', '')
store.commit('user/setAccessToken', '')
}
export default service
export default {
userInfo: state => state.user.userInfo,
isLogin: state => !!state.user.uid,
}
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import user from './modules/user'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
user,
},
getters,
})
export default store
/* eslint-disable no-undef */
// import request from '@/plugins/request'
export default {
namespaced: true,
state() {
return {
userInfo: uni.getStorageSync('userInfo') || {},
code: uni.getStorageSync('code') || '',
uid: uni.getStorageSync('uid') || '',
accessToken: uni.getStorageSync('accessToken') || '',
}
},
mutations: {
setUserInfo(state, data) {
uni.setStorageSync('userInfo', data)
state.userInfo = data
},
setCode(state, data) {
uni.setStorageSync('code', data)
state.code = data
},
setUid(state, data) {
uni.setStorageSync('uid', data)
state.uid = data
},
setAccessToken(state, data) {
uni.setStorageSync('accessToken', data)
state.accessToken = data
},
},
actions: {
uniLogin({ commit }) {
return new Promise((resolve, reject) => {
uni.login({
success(res) {
commit('setCode', res.code)
resolve()
},
fail() {
commit('setCode', '')
uni.showToast({
title: '获取code失败,请稍后重试',
icon: 'none',
})
reject()
},
})
})
},
login({ commit }, { code, encryptedData, iv }) {
return new Promise(async (resolve, reject) => {
// TODO 调用登录接口,设置store数据
resolve()
})
},
},
}
@import 'uview-ui/theme.scss';
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
$uni-color-primary: #007aff;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d;
/* 文字基本颜色 */
$uni-text-color: #333; // 基本色
$uni-text-color-inverse: #fff; // 反色
$uni-text-color-grey: #999; // 辅助灰色,如加载更多的提示信息
$uni-text-color-placeholder: #808080;
$uni-text-color-disable: #c0c0c0;
/* 背景颜色 */
$uni-bg-color: #fff;
$uni-bg-color-grey: #f8f8f8;
$uni-bg-color-hover: #f1f1f1; // 点击状态颜色
$uni-bg-color-mask: rgba(0, 0, 0, 0.4); // 遮罩颜色
/* 边框颜色 */
$uni-border-color: #c8c7cc;
/* 尺寸变量 */
/* 文字尺寸 */
$uni-font-size-sm: 12px;
$uni-font-size-base: 14px;
$uni-font-size-lg: 16;
/* 图片尺寸 */
$uni-img-size-sm: 20px;
$uni-img-size-base: 26px;
$uni-img-size-lg: 40px;
/* Border Radius */
$uni-border-radius-sm: 2px;
$uni-border-radius-base: 3px;
$uni-border-radius-lg: 6px;
$uni-border-radius-circle: 50%;
/* 水平间距 */
$uni-spacing-row-sm: 5px;
$uni-spacing-row-base: 10px;
$uni-spacing-row-lg: 15px;
/* 垂直间距 */
$uni-spacing-col-sm: 4px;
$uni-spacing-col-base: 8px;
$uni-spacing-col-lg: 12px;
/* 透明度 */
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
/* 文章场景相关 */
$uni-color-title: #2c405a; // 文章标题颜色
$uni-font-size-title: 20px;
$uni-color-subtitle: #555; // 二级标题颜色
$uni-font-size-subtitle: 18px;
$uni-color-paragraph: #3f536e; // 文章段落颜色
$uni-font-size-paragraph: 15px;
\ No newline at end of file
import request from '@/plugins/request'
// 埋点
export const setTrackData = ({ events = [], beforeEvent = null }) => {
// 统一添加埋点字段 action_time
events.forEach(item => {
if (!item.action_time) {
item.action_time = Date.now()
}
})
// 埋点参数-前置事件,接口入参默认值
const beforeEventDefault = {
action_time: Date.now(),
event_id: '',
event_custom_properties: {
part: '',
position: '',
element: '',
},
}
return new Promise((resolve, reject) => {
// 获取设备信息
// eslint-disable-next-line no-undef
uni.getSystemInfo({
success(res) {
// 发送埋点请求
try {
const result = request.post(
'/dmp-event/v1/events/bulk',
{
app_name: '', // 应用名称,根据实际项目定义填写
os_type: 4, // 操作系统类型,小程序
time: Date.now(),
os: res.system,
os_version: res.version,
model: res.model,
screen_height: res.screenHeight,
screen_width: res.screenWidth,
wifi: res.wifiEnabled ? 1 : 0, // Wi-Fi 的系统开关
manufacturer: '',
ip: '',
before_event: beforeEvent || beforeEventDefault,
events,
},
{
// 埋头中统一的请求头字段
headers: {
fid: res.deviceId,
osType: 4,
version: res.version,
appName: 'ydllisten', // 应用名称
},
},
)
resolve(result)
} catch (e) {
reject(e)
}
},
fail(res) {
reject(res)
},
})
})
}
module.exports = {
transpileDependencies: ['uview-ui'],
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment