Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uni-app-template
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenzhiqiang
uni-app-template
Commits
82a6f534
Commit
82a6f534
authored
Jul 01, 2022
by
szq233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: eslint
parent
62e8493f
Pipeline
#1042
canceled with stages
Changes
23
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
852 additions
and
167 deletions
+852
-167
.eslintrc.js
.eslintrc.js
+35
-0
README.md
README.md
+7
-3
babel.config.js
babel.config.js
+7
-7
package.json
package.json
+8
-0
public/index.html
public/index.html
+1
-2
sfc.d.ts
sfc.d.ts
+7
-6
shims-vue.d.ts
shims-vue.d.ts
+2
-2
src/App.vue
src/App.vue
+19
-19
src/common/http.interceptor.ts
src/common/http.interceptor.ts
+1
-1
src/components/register.ts
src/components/register.ts
+2
-2
src/main.ts
src/main.ts
+3
-3
src/models/uview/index.ts
src/models/uview/index.ts
+1
-0
src/pages/about/index.vue
src/pages/about/index.vue
+1
-1
src/pages/home/index.vue
src/pages/home/index.vue
+3
-2
src/pages/noAccess/index.vue
src/pages/noAccess/index.vue
+1
-1
src/pages/profile/index.vue
src/pages/profile/index.vue
+1
-1
src/router/index.ts
src/router/index.ts
+6
-6
src/store/$u.mixin.ts
src/store/$u.mixin.ts
+15
-15
src/store/index.ts
src/store/index.ts
+47
-48
src/utils/manifestJson.js
src/utils/manifestJson.js
+5
-4
src/utils/pagesJson.js
src/utils/pagesJson.js
+2
-1
vue.config.js
vue.config.js
+18
-20
yarn.lock
yarn.lock
+660
-23
No files found.
.eslintrc.js
0 → 100644
View file @
82a6f534
module
.
exports
=
{
root
:
true
,
env
:
{
browser
:
true
,
es2021
:
true
,
node
:
true
},
extends
:
[
'
plugin:vue/essential
'
,
'
standard
'
],
globals
:
{
uni
:
'
readonly
'
,
dd
:
'
readonly
'
,
plus
:
'
readonly
'
,
wx
:
'
readonly
'
},
parserOptions
:
{
ecmaVersion
:
'
latest
'
,
parser
:
'
@typescript-eslint/parser
'
,
sourceType
:
'
module
'
},
plugins
:
[
'
vue
'
,
'
@typescript-eslint
'
],
rules
:
{
camelcase
:
'
off
'
,
semi
:
'
error
'
,
'
import/first
'
:
'
off
'
,
'
no-console
'
:
'
off
'
,
'
no-debugger
'
:
process
.
env
.
NODE_ENV
===
'
production
'
?
'
warn
'
:
'
off
'
,
'
vue/multi-word-component-names
'
:
'
off
'
}
}
README.md
View file @
82a6f534
# uni-app-template
# uni-app-template
## Project setup
## Project setup
```
```
shell
yarn
install
yarn
install
```
```
### Compiles and hot-reloads for development
### Compiles and hot-reloads for development
```
```
shell
yarn serve
yarn serve
```
```
### Compiles and minifies for production
### Compiles and minifies for production
```
```
shell
yarn build
yarn build
```
```
### Customize configuration
### Customize configuration
See
[
Configuration Reference
](
https://cli.vuejs.org/config/
)
.
See
[
Configuration Reference
](
https://cli.vuejs.org/config/
)
.
babel.config.js
View file @
82a6f534
const
plugins
=
[]
const
plugins
=
[]
if
(
process
.
env
.
UNI_OPT_TREESHAKINGNG
)
{
if
(
process
.
env
.
UNI_OPT_TREESHAKINGNG
)
{
plugins
.
push
(
require
(
'
@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js
'
))
plugins
.
push
(
require
(
'
@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js
'
))
}
}
if
(
if
(
(
(
process
.
env
.
UNI_PLATFORM
===
'
app-plus
'
&&
process
.
env
.
UNI_PLATFORM
===
'
app-plus
'
&&
process
.
env
.
UNI_USING_V8
process
.
env
.
UNI_USING_V8
...
@@ -12,7 +12,7 @@ if (
...
@@ -12,7 +12,7 @@ if (
(
(
process
.
env
.
UNI_PLATFORM
===
'
h5
'
&&
process
.
env
.
UNI_PLATFORM
===
'
h5
'
&&
process
.
env
.
UNI_H5_BROWSER
===
'
builtin
'
process
.
env
.
UNI_H5_BROWSER
===
'
builtin
'
)
)
)
{
)
{
const
path
=
require
(
'
path
'
)
const
path
=
require
(
'
path
'
)
...
@@ -42,8 +42,8 @@ process.UNI_LIBRARIES.forEach(libraryName => {
...
@@ -42,8 +42,8 @@ process.UNI_LIBRARIES.forEach(libraryName => {
plugins
.
push
([
plugins
.
push
([
'
import
'
,
'
import
'
,
{
{
'
libraryName
'
:
libraryName
,
libraryName
,
'
customName
'
:
(
name
)
=>
{
customName
:
(
name
)
=>
{
return
`
${
libraryName
}
/lib/
${
name
}
/
${
name
}
`
return
`
${
libraryName
}
/lib/
${
name
}
/
${
name
}
`
}
}
}
}
...
@@ -60,4 +60,4 @@ module.exports = {
...
@@ -60,4 +60,4 @@ module.exports = {
]
]
],
],
plugins
plugins
}
}
package.json
View file @
82a6f534
...
@@ -95,11 +95,19 @@
...
@@ -95,11 +95,19 @@
"
@dcloudio/webpack-uni-mp-loader
"
:
"
^2.0.1-34920220609002
"
,
"
@dcloudio/webpack-uni-mp-loader
"
:
"
^2.0.1-34920220609002
"
,
"
@dcloudio/webpack-uni-pages-loader
"
:
"
^2.0.1-34920220609002
"
,
"
@dcloudio/webpack-uni-pages-loader
"
:
"
^2.0.1-34920220609002
"
,
"
@types/node
"
:
"
^18.0.0
"
,
"
@types/node
"
:
"
^18.0.0
"
,
"
@typescript-eslint/eslint-plugin
"
:
"
^5.30.0
"
,
"
@typescript-eslint/parser
"
:
"
^5.30.0
"
,
"
@vue/cli-plugin-babel
"
:
"
~4.5.13
"
,
"
@vue/cli-plugin-babel
"
:
"
~4.5.13
"
,
"
@vue/cli-plugin-typescript
"
:
"
~4.5.11
"
,
"
@vue/cli-plugin-typescript
"
:
"
~4.5.11
"
,
"
@vue/cli-service
"
:
"
~4.5.13
"
,
"
@vue/cli-service
"
:
"
~4.5.13
"
,
"
babel-plugin-import
"
:
"
^1.11.0
"
,
"
babel-plugin-import
"
:
"
^1.11.0
"
,
"
cross-env
"
:
"
^7.0.2
"
,
"
cross-env
"
:
"
^7.0.2
"
,
"
eslint
"
:
"
^8.0.1
"
,
"
eslint-config-standard
"
:
"
^17.0.0
"
,
"
eslint-plugin-import
"
:
"
^2.25.2
"
,
"
eslint-plugin-n
"
:
"
^15.0.0
"
,
"
eslint-plugin-promise
"
:
"
^6.0.0
"
,
"
eslint-plugin-vue
"
:
"
^9.1.1
"
,
"
jest
"
:
"
^25.4.0
"
,
"
jest
"
:
"
^25.4.0
"
,
"
mini-types
"
:
"
*
"
,
"
mini-types
"
:
"
*
"
,
"
miniprogram-api-typings
"
:
"
*
"
,
"
miniprogram-api-typings
"
:
"
*
"
,
...
...
public/index.html
View file @
82a6f534
<!DOCTYPE html>
<!DOCTYPE html>
<html
lang=
"zh-CN"
>
<html
lang=
"zh-CN"
>
<head>
<head>
<meta
charset=
"utf-8"
>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<title>
<title>
<
%=
htmlWebpackPlugin.options.title
%
>
<
%=
htmlWebpackPlugin.options.title
%
>
</title>
</title>
<link
rel=
"icon"
href=
"<%= BASE_URL %>static/logo.png"
>
<script>
<script>
var
coverSupport
=
'
CSS
'
in
window
&&
typeof
CSS
.
supports
===
'
function
'
&&
(
CSS
.
supports
(
'
top: env(a)
'
)
||
CSS
.
supports
(
'
top: constant(a)
'
))
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
'
:
''
)
+
'
" />
'
)
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
'
:
''
)
+
'
" />
'
)
...
@@ -21,5 +21,4 @@
...
@@ -21,5 +21,4 @@
<div
id=
"app"
></div>
<div
id=
"app"
></div>
<!-- built files will be auto injected -->
<!-- built files will be auto injected -->
</body>
</body>
</html>
</html>
\ No newline at end of file
sfc.d.ts
View file @
82a6f534
import
Vue
from
'
vue
'
;
/* eslint-disable */
import
{
$u
}
from
'
./src/models/uview
'
;
// 引入this.$u的相关类型定义
import
Vue
from
'
vue
'
import
{
GlobalMixins
}
from
'
./src/store/model
'
;
// 引入混入到全局的vuex中state中属性类型扩展
import
{
$u
}
from
'
./src/models/uview
'
// 引入this.$u的相关类型定义
declare
module
"
vue/types/options
"
{
import
{
GlobalMixins
}
from
'
./src/store/model
'
// 引入混入到全局的vuex中state中属性类型扩展
type
Hooks
=
App
.
AppInstance
&
Page
.
PageInstance
;
declare
module
'
vue/types/options
'
{
type
Hooks
=
App
.
AppInstance
&
Page
.
PageInstance
interface
ComponentOptions
<
V
extends
Vue
>
extends
Hooks
{
interface
ComponentOptions
<
V
extends
Vue
>
extends
Hooks
{
mpType
?:
string
;
mpType
?:
string
;
}
}
...
@@ -14,4 +15,4 @@ declare module 'vue/types/vue' {
...
@@ -14,4 +15,4 @@ declare module 'vue/types/vue' {
}
}
}
}
declare
var
ROUTES
=
[]
;
declare
var
ROUTES
=
[]
shims-vue.d.ts
View file @
82a6f534
declare
module
'
*.vue
'
{
declare
module
'
*.vue
'
{
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
export
default
Vue
;
export
default
Vue
}
}
declare
module
'
uview-ui
'
declare
module
'
uview-ui
'
...
...
src/App.vue
View file @
82a6f534
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
export
default
Vue
.
extend
({
export
default
Vue
.
extend
({
mpType
:
'
app
'
,
mpType
:
'
app
'
,
onLaunch
()
{
onLaunch
()
{
// 隐藏原生的tabBar,只使用自定义的tabbar组件
// 隐藏原生的tabBar,只使用自定义的tabbar组件
uni
.
hideTabBar
({
uni
.
hideTabBar
({
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
log
(
res
)
console
.
log
(
res
)
}
}
})
})
console
.
log
(
'
App Launch
'
)
console
.
log
(
'
App Launch
'
)
},
},
onShow
()
{
onShow
()
{
console
.
log
(
'
App Show
'
)
console
.
log
(
'
App Show
'
)
},
},
onHide
()
{
onHide
()
{
console
.
log
(
'
App Hide
'
)
console
.
log
(
'
App Hide
'
)
}
}
});
})
</
script
>
</
script
>
<
style
lang=
"scss"
>
<
style
lang=
"scss"
>
...
...
src/common/http.interceptor.ts
View file @
82a6f534
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// 同时,我们也可以在此使用getApp().globalData,如果你把token放在getApp().globalData的话,也是可以使用的
// 同时,我们也可以在此使用getApp().globalData,如果你把token放在getApp().globalData的话,也是可以使用的
const
install
=
(
Vue
:
any
,
vm
:
any
)
=>
{
const
install
=
(
Vue
:
any
,
vm
:
any
)
=>
{
Vue
.
prototype
.
$u
.
http
.
setConfig
({
Vue
.
prototype
.
$u
.
http
.
setConfig
({
baseUrl
:
`https://test.test/api`
,
baseUrl
:
'
https://test.test/api
'
,
// 如果将此值设置为true,拦截回调中将会返回服务端返回的所有数据response,而不是response.data
// 如果将此值设置为true,拦截回调中将会返回服务端返回的所有数据response,而不是response.data
// 设置为true后,就需要在this.$u.http.interceptor.response进行多一次的判断,请打印查看具体值
// 设置为true后,就需要在this.$u.http.interceptor.response进行多一次的判断,请打印查看具体值
// 设置自定义头部content-type
// 设置自定义头部content-type
...
...
src/components/register.ts
View file @
82a6f534
import
Vue
from
'
vue
'
import
Vue
from
'
vue
'
import
{
Component
}
from
'
vue-property-decorator
'
//
import { Component } from 'vue-property-decorator'
import
uView
from
"
uview-ui
"
;
import
uView
from
'
uview-ui
'
import
Loading
from
'
./loading/loading.vue
'
import
Loading
from
'
./loading/loading.vue
'
import
TabBar
from
'
./tabbar/index.vue
'
import
TabBar
from
'
./tabbar/index.vue
'
import
scss
from
'
@/uni.scss
'
import
scss
from
'
@/uni.scss
'
...
...
src/main.ts
View file @
82a6f534
...
@@ -3,7 +3,7 @@ import App from './App.vue'
...
@@ -3,7 +3,7 @@ import App from './App.vue'
import
store
from
'
@/store
'
import
store
from
'
@/store
'
import
eruda
from
'
eruda
'
import
eruda
from
'
eruda
'
import
{
router
,
RouterMount
}
from
'
./router
'
import
{
router
,
RouterMount
}
from
'
./router
'
import
'
@/components/register
'
;
import
'
@/components/register
'
import
{
VuexMixin
}
from
'
@/store/$u.mixin
'
import
{
VuexMixin
}
from
'
@/store/$u.mixin
'
...
@@ -14,7 +14,7 @@ Vue.mixin(VuexMixin)
...
@@ -14,7 +14,7 @@ Vue.mixin(VuexMixin)
// if (process.env.VUE_APP_ENV === 'test') {
// if (process.env.VUE_APP_ENV === 'test') {
// 默认开启eruda调试台,这里可以用环境变量判断开启关闭
// 默认开启eruda调试台,这里可以用环境变量判断开启关闭
eruda
.
init
();
eruda
.
init
()
// }
// }
const
app
=
new
App
({
const
app
=
new
App
({
...
@@ -34,5 +34,5 @@ RouterMount(app, router, '#app')
...
@@ -34,5 +34,5 @@ RouterMount(app, router, '#app')
// #endif
// #endif
// #ifndef H5
// #ifndef H5
app
.
$mount
()
;
//
为了兼容小程序及app端必须这样写才有效果
app
.
$mount
()
//
为了兼容小程序及app端必须这样写才有效果
// #endif
// #endif
src/models/uview/index.ts
View file @
82a6f534
...
@@ -12,6 +12,7 @@ interface UView {
...
@@ -12,6 +12,7 @@ interface UView {
/**
/**
* 此属性用于获取设备的信息,相当于uni.getSystemInfoSync()的效果
* 此属性用于获取设备的信息,相当于uni.getSystemInfoSync()的效果
*/
*/
// eslint-disable-next-line no-undef
sys
():
UniNamespace
.
GetSystemInfoResult
sys
():
UniNamespace
.
GetSystemInfoResult
queryParams
(
data
:
any
,
isPrefix
?:
boolean
,
arrayFormat
?:
string
):
string
queryParams
(
data
:
any
,
isPrefix
?:
boolean
,
arrayFormat
?:
string
):
string
route
(
options
:
any
,
params
:
any
):
void
route
(
options
:
any
,
params
:
any
):
void
...
...
src/pages/about/index.vue
View file @
82a6f534
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Prop
,
Watch
,
Emit
,
Ref
}
from
'
vue-property-decorator
'
;
import
{
Vue
,
Component
}
from
'
vue-property-decorator
'
@
Component
@
Component
export
default
class
About
extends
Vue
{
export
default
class
About
extends
Vue
{
...
...
src/pages/home/index.vue
View file @
82a6f534
...
@@ -10,12 +10,13 @@
...
@@ -10,12 +10,13 @@
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Watch
,
Emit
,
Ref
}
from
'
vue-property-decorator
'
;
// Vue, Component, Prop, Watch, Emit, Ref
import
{
Vue
,
Component
}
from
'
vue-property-decorator
'
@
Component
@
Component
export
default
class
Home
extends
Vue
{
export
default
class
Home
extends
Vue
{
private
title
=
'
这里是首页
'
private
title
=
'
这里是首页
'
onShow
()
{
onShow
()
{
this
.
$u
.
toast
(
'
首页
'
)
this
.
$u
.
toast
(
'
首页
'
)
this
.
$u
.
vuex
(
'
vuex_user
'
,
{
this
.
$u
.
vuex
(
'
vuex_user
'
,
{
name
:
'
测试
'
,
name
:
'
测试
'
,
...
...
src/pages/noAccess/index.vue
View file @
82a6f534
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Prop
,
Watch
,
Emit
,
Ref
}
from
'
vue-property-decorator
'
;
import
{
Vue
,
Component
}
from
'
vue-property-decorator
'
@
Component
@
Component
export
default
class
NoAccess
extends
Vue
{
export
default
class
NoAccess
extends
Vue
{
...
...
src/pages/profile/index.vue
View file @
82a6f534
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Prop
,
Watch
,
Emit
,
Ref
}
from
'
vue-property-decorator
'
;
import
{
Vue
,
Component
}
from
'
vue-property-decorator
'
@
Component
@
Component
export
default
class
About
extends
Vue
{
export
default
class
About
extends
Vue
{
...
...
src/router/index.ts
View file @
82a6f534
import
{
RouterMount
,
createRouter
,
RoutesRule
}
from
'
uni-simple-router
'
;
import
{
RouterMount
,
createRouter
,
RoutesRule
}
from
'
uni-simple-router
'
const
pages
=
require
(
'
./pages.ts
'
)
const
pages
=
require
(
'
./pages.ts
'
)
const
RouterPages
:
RoutesRule
[]
=
[
const
RouterPages
:
RoutesRule
[]
=
[
...
@@ -18,12 +18,12 @@ const router = createRouter({
...
@@ -18,12 +18,12 @@ const router = createRouter({
return
{
name
:
'
404
'
}
return
{
name
:
'
404
'
}
}
}
}]
}]
})
;
})
// 路由前置守卫
// 路由前置守卫
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
next
();
next
()
})
;
})
// 路由后置守卫
// 路由后置守卫
router
.
afterEach
((
to
,
from
)
=>
{
router
.
afterEach
((
to
,
from
)
=>
{
...
@@ -31,6 +31,6 @@ router.afterEach((to, from) => {
...
@@ -31,6 +31,6 @@ router.afterEach((to, from) => {
})
})
export
{
export
{
router
,
router
,
RouterMount
RouterMount
}
}
src/store/$u.mixin.ts
View file @
82a6f534
import
{
Component
,
Vue
}
from
'
vue-property-decorator
'
import
{
Component
,
Vue
}
from
'
vue-property-decorator
'
import
{
mapState
}
from
'
vuex
'
import
{
mapState
}
from
'
vuex
'
import
store
from
"
./index
"
import
store
from
'
./index
'
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let
$uStoreKey
:
string
[]
=
[]
;
let
$uStoreKey
:
string
[]
=
[]
try
{
try
{
$uStoreKey
=
store
.
state
?
Object
.
keys
(
store
.
state
)
:
[]
;
$uStoreKey
=
store
.
state
?
Object
.
keys
(
store
.
state
)
:
[]
}
catch
(
e
)
{
}
}
catch
(
e
)
{
}
@
Component
({
@
Component
({
computed
:
{
computed
:
{
...
@@ -14,16 +14,16 @@ try{
...
@@ -14,16 +14,16 @@ try{
}
}
})
})
export
class
VuexMixin
extends
Vue
{
export
class
VuexMixin
extends
Vue
{
private
created
()
{
private
created
()
{
// 此处的types声明在src/models/uview/index.ts定义
// 此处的types声明在src/models/uview/index.ts定义
// 将vuex方法挂在到$u中
// 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
this
.
$u
.
vuex
=
(
name
:
string
,
value
:
any
)
=>
{
this
.
$u
.
vuex
=
(
name
:
string
,
value
:
any
)
=>
{
this
.
$store
.
commit
(
'
$uStore
'
,
{
this
.
$store
.
commit
(
'
$uStore
'
,
{
name
,
value
name
,
value
})
})
}
}
// 以下是一些挂载到$u的自定义工具方法
// 以下是一些挂载到$u的自定义工具方法
// rpx转换为px
// rpx转换为px
...
@@ -34,5 +34,5 @@ export class VuexMixin extends Vue {
...
@@ -34,5 +34,5 @@ export class VuexMixin extends Vue {
this
.
$u
.
px2rpx
=
(
px
:
number
)
=>
{
this
.
$u
.
px2rpx
=
(
px
:
number
)
=>
{
return
px
/
(
uni
.
upx2px
(
100
)
/
100
)
return
px
/
(
uni
.
upx2px
(
100
)
/
100
)
}
}
}
}
}
}
src/store/index.ts
View file @
82a6f534
import
Vue
from
'
vue
'
import
Vue
from
'
vue
'
import
Vuex
from
'
vuex
'
import
Vuex
,
{
Store
}
from
'
vuex
'
import
{
Store
}
from
'
vuex
'
;
Vue
.
use
(
Vuex
)
Vue
.
use
(
Vuex
)
let
lifeData
:
any
=
{}
;
let
lifeData
:
any
=
{}
// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
try
{
try
{
lifeData
=
uni
.
getStorageSync
(
'
lifeData
'
);
lifeData
=
uni
.
getStorageSync
(
'
lifeData
'
)
}
catch
(
e
)
{
}
}
catch
(
e
)
{
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
const
saveStateKeys
=
[
'
vuex_user
'
,
'
vuex_token
'
]
;
const
saveStateKeys
=
[
'
vuex_user
'
,
'
vuex_token
'
]
// 保存变量到本地存储中
// 保存变量到本地存储中
const
saveLifeData
=
function
(
key
:
string
,
value
:
any
)
{
const
saveLifeData
=
function
(
key
:
string
,
value
:
any
)
{
// 判断变量名是否在需要存储的数组中
// 判断变量名是否在需要存储的数组中
if
(
saveStateKeys
.
indexOf
(
key
)
!
=
-
1
)
{
if
(
saveStateKeys
.
indexOf
(
key
)
!=
=
-
1
)
{
// 获取本地存储的lifeData对象,将变量添加到对象中
// 获取本地存储的lifeData对象,将变量添加到对象中
let
tmp
=
uni
.
getStorageSync
(
'
lifeData
'
);
let
tmp
=
uni
.
getStorageSync
(
'
lifeData
'
)
// 第一次打开APP,不存在lifeData变量,故放一个{}空对象
// 第一次打开APP,不存在lifeData变量,故放一个{}空对象
tmp
=
tmp
?
tmp
:
{};
tmp
=
tmp
||
{}
tmp
[
key
]
=
value
;
tmp
[
key
]
=
value
// 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中
// 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中
uni
.
setStorageSync
(
'
lifeData
'
,
tmp
);
uni
.
setStorageSync
(
'
lifeData
'
,
tmp
)
}
}
}
}
const
store
=
new
Vuex
.
Store
({
const
store
=
new
Vuex
.
Store
({
state
:
{
state
:
{
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
vuex_user
:
lifeData
.
vuex_user
?
lifeData
.
vuex_user
:
{
name
:
'
测试名
'
,
corpid
:
'
2333
'
},
vuex_user
:
lifeData
.
vuex_user
?
lifeData
.
vuex_user
:
{
name
:
'
测试名
'
,
corpid
:
'
2333
'
},
vuex_token
:
lifeData
.
vuex_token
?
lifeData
.
vuex_token
:
''
,
vuex_token
:
lifeData
.
vuex_token
?
lifeData
.
vuex_token
:
''
,
// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
vuex_version
:
'
1.0.1
'
,
vuex_version
:
'
1.0.1
'
},
},
mutations
:
{
mutations
:
{
$uStore
(
state
:
any
,
payload
:
any
)
{
$uStore
(
state
:
any
,
payload
:
any
)
{
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
le
t
nameArr
=
payload
.
name
.
split
(
'
.
'
)
as
string
[]
cons
t
nameArr
=
payload
.
name
.
split
(
'
.
'
)
as
string
[]
let
saveKey
=
''
;
let
saveKey
=
''
let
len
=
nameArr
.
length
;
const
len
=
nameArr
.
length
if
(
len
>=
2
)
{
if
(
len
>=
2
)
{
let
obj
=
state
[
nameArr
[
0
]];
let
obj
=
state
[
nameArr
[
0
]]
for
(
let
i
=
1
;
i
<
len
-
1
;
i
++
)
{
for
(
let
i
=
1
;
i
<
len
-
1
;
i
++
)
{
obj
=
obj
[
nameArr
[
i
]]
obj
=
obj
[
nameArr
[
i
]]
}
}
// obj[nameArr[len - 1]] = payload.value;
// obj[nameArr[len - 1]] = payload.value;
Vue
.
set
(
state
[
nameArr
[
0
]],
nameArr
[
len
-
1
],
payload
.
value
)
Vue
.
set
(
state
[
nameArr
[
0
]],
nameArr
[
len
-
1
],
payload
.
value
)
saveKey
=
payload
.
name
saveKey
=
payload
.
name
}
else
{
}
else
{
// 单层级变量,在state就是一个普通变量的情况
// 单层级变量,在state就是一个普通变量的情况
// state[payload.name] = payload.value;
// state[payload.name] = payload.value;
Vue
.
set
(
state
,
payload
.
name
,
payload
.
value
)
Vue
.
set
(
state
,
payload
.
name
,
payload
.
value
)
saveKey
=
payload
.
name
;
saveKey
=
payload
.
name
}
}
// 保存变量到本地,见顶部函数定义
// 保存变量到本地,见顶部函数定义
saveLifeData
(
saveKey
,
state
[
saveKey
])
saveLifeData
(
saveKey
,
state
[
saveKey
])
}
}
}
}
})
as
Store
<
any
>
})
as
Store
<
any
>
export
default
store
export
default
store
src/utils/manifestJson.js
View file @
82a6f534
const
fs
=
require
(
'
fs
'
)
const
fs
=
require
(
'
fs
'
)
let
versionCode
=
'
0.0.1
'
const
path
=
require
(
'
path
'
)
const
versionCode
=
'
0.0.1
'
// try {
// try {
// const execSync = require('child_process').execSync // 同步子进程
// const execSync = require('child_process').execSync // 同步子进程
// const commit = execSync('git show -s --format=%d').toString().trim()
// const commit = execSync('git show -s --format=%d').toString().trim()
...
@@ -15,7 +16,7 @@ let versionCode = '0.0.1'
...
@@ -15,7 +16,7 @@ let versionCode = '0.0.1'
* qa----测试
* qa----测试
* @type {{qa: string, prod: string}}
* @type {{qa: string, prod: string}}
*/
*/
const
paths
=
{
const
paths
=
{
qa
:
'
https://测试环境域名地址/
'
+
versionCode
+
'
/build/h5
'
,
qa
:
'
https://测试环境域名地址/
'
+
versionCode
+
'
/build/h5
'
,
prod
:
'
https://正式环境域名地址/
'
+
versionCode
+
'
/build/h5
'
prod
:
'
https://正式环境域名地址/
'
+
versionCode
+
'
/build/h5
'
}
}
...
@@ -121,7 +122,7 @@ const data = {
...
@@ -121,7 +122,7 @@ const data = {
}
}
}
}
},
},
publicPath
:
publicPath
,
publicPath
,
title
:
'
h5模板
'
,
title
:
'
h5模板
'
,
router
:
{
router
:
{
mode
:
'
history
'
,
mode
:
'
history
'
,
...
@@ -142,7 +143,7 @@ const data = {
...
@@ -142,7 +143,7 @@ const data = {
const
env
=
process
.
env
.
VUE_APP_ENV
===
'
online
'
?
'
正式环境
'
:
'
测试环境
'
const
env
=
process
.
env
.
VUE_APP_ENV
===
'
online
'
?
'
正式环境
'
:
'
测试环境
'
console
.
log
(
`uni-app: publicPath-
${
env
}
:
${
publicPath
}
`
)
console
.
log
(
`uni-app: publicPath-
${
env
}
:
${
publicPath
}
`
)
fs
.
writeFile
(
fs
.
writeFile
(
`
${
__dirname
}
/../manifest.json`
,
path
.
join
(
__dirname
,
'
../manifest.json
'
)
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
data
),
(
e
)
=>
(
e
?
console
.
error
(
e
)
:
console
.
log
(
'
manifest.json 配置文件更新成功
'
))
(
e
)
=>
(
e
?
console
.
error
(
e
)
:
console
.
log
(
'
manifest.json 配置文件更新成功
'
))
)
)
src/utils/pagesJson.js
View file @
82a6f534
const
fs
=
require
(
'
fs
'
)
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
pages
=
require
(
'
../router/pages.ts
'
)
const
pages
=
require
(
'
../router/pages.ts
'
)
const
tabBar
=
require
(
'
./tabbarList
'
)
const
tabBar
=
require
(
'
./tabbarList
'
)
...
@@ -28,7 +29,7 @@ const data = {
...
@@ -28,7 +29,7 @@ const data = {
}
}
}
}
fs
.
writeFile
(
fs
.
writeFile
(
`
${
__dirname
}
/../pages.json`
,
path
.
join
(
__dirname
,
'
../pages.json
'
)
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
data
),
(
e
)
=>
(
e
?
console
.
error
(
e
)
:
console
.
log
(
'
pages.json 配置文件更新成功
'
))
(
e
)
=>
(
e
?
console
.
error
(
e
)
:
console
.
log
(
'
pages.json 配置文件更新成功
'
))
)
)
vue.config.js
View file @
82a6f534
//vue.config.js
//
vue.config.js
const
TransformPages
=
require
(
'
uni-read-pages
'
)
const
TransformPages
=
require
(
'
uni-read-pages
'
)
const
ForkTsCheckerWebpackPlugin
=
require
(
'
fork-ts-checker-webpack-plugin
'
)
const
ForkTsCheckerWebpackPlugin
=
require
(
'
fork-ts-checker-webpack-plugin
'
)
const
{
webpack
}
=
new
TransformPages
()
const
{
webpack
}
=
new
TransformPages
()
module
.
exports
=
{
module
.
exports
=
{
configureWebpack
:
{
plugins
:
[
new
webpack
.
DefinePlugin
({
ROUTES
:
webpack
.
DefinePlugin
.
runtimeValue
(()
=>
{
const
tfPages
=
new
TransformPages
({
includes
:
[
'
path
'
,
'
name
'
,
'
aliasPath
'
]
});
return
JSON
.
stringify
(
tfPages
.
routes
)
},
true
)
})
]
},
configureWebpack
:
(
config
)
=>
{
configureWebpack
:
(
config
)
=>
{
config
.
plugins
=
[
new
webpack
.
DefinePlugin
({
ROUTES
:
webpack
.
DefinePlugin
.
runtimeValue
(()
=>
{
const
tfPages
=
new
TransformPages
({
includes
:
[
'
path
'
,
'
name
'
,
'
aliasPath
'
]
})
return
JSON
.
stringify
(
tfPages
.
routes
)
},
true
)
})
]
// 限制工作线程使用1024MB内存
// 限制工作线程使用1024MB内存
// get a reference to the existing ForkTsCheckerWebpackPlugin
// get a reference to the existing ForkTsCheckerWebpackPlugin
const
existingForkTsChecker
=
config
.
plugins
.
filter
(
const
existingForkTsChecker
=
config
.
plugins
.
filter
(
p
=>
p
instanceof
ForkTsCheckerWebpackPlugin
,
p
=>
p
instanceof
ForkTsCheckerWebpackPlugin
)[
0
]
)[
0
]
// remove the existing ForkTsCheckerWebpackPlugin
// remove the existing ForkTsCheckerWebpackPlugin
// so that we can replace it with our modified version
// so that we can replace it with our modified version
config
.
plugins
=
config
.
plugins
.
filter
(
config
.
plugins
=
config
.
plugins
.
filter
(
p
=>
!
(
p
instanceof
ForkTsCheckerWebpackPlugin
)
,
p
=>
!
(
p
instanceof
ForkTsCheckerWebpackPlugin
)
)
;
)
// copy the options from the original ForkTsCheckerWebpackPlugin
// copy the options from the original ForkTsCheckerWebpackPlugin
// instance and add the memoryLimit property
// instance and add the memoryLimit property
const
forkTsCheckerOptions
=
existingForkTsChecker
.
options
;
const
forkTsCheckerOptions
=
existingForkTsChecker
.
options
forkTsCheckerOptions
.
memoryLimit
=
1024
;
forkTsCheckerOptions
.
memoryLimit
=
1024
config
.
plugins
.
push
(
new
ForkTsCheckerWebpackPlugin
(
forkTsCheckerOptions
))
;
config
.
plugins
.
push
(
new
ForkTsCheckerWebpackPlugin
(
forkTsCheckerOptions
))
},
},
transpileDependencies
:
[
'
uview-ui
'
]
transpileDependencies
:
[
'
uview-ui
'
]
}
}
yarn.lock
View file @
82a6f534
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment