Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
self-support
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李俊赕
self-support
Commits
3342dd74
Commit
3342dd74
authored
Apr 09, 2021
by
李俊赕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve-request
parent
46f3fbb7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
15 deletions
+166
-15
.env.dev.js
.env.dev.js
+11
-5
.env.prod.js
.env.prod.js
+8
-1
.env.test.js
.env.test.js
+11
-1
http.interceptor.js
src/common/http.interceptor.js
+8
-6
main.js
src/main.js
+3
-2
$u.mixin.js
src/store/$u.mixin.js
+24
-0
index.js
src/store/index.js
+101
-0
No files found.
.env.dev.js
View file @
3342dd74
const
UNI_APP
=
{
BASE_API
:
'/dev-api'
}
module
.
exports
=
UNI_APP
;
\ No newline at end of file
const
UNI_APP
=
{
ucenterUrl
:
{
apiUrl
:
'https://rest-u.banshouhui.com'
,
//php端域名请求头
xueUrl
:
'https://xue.banshouhui.com'
,
//学院
banshou
:
'https://m.banshou.com'
,
//扳手app
},
systemUrl
:
{
apiUrl
:
'https://system.banshouhui.com'
,
//java端域名请求头
}
}
module
.
exports
=
UNI_APP
;
.env.prod.js
View file @
3342dd74
const
UNI_APP
=
{
BASE_API
:
'/prod-api'
ucenterUrl
:
{
apiUrl
:
'https://rest-u.banshouhui.com'
,
//php端域名请求头
xueUrl
:
'https://xue.banshouhui.com'
,
//学院
banshou
:
'https://m.banshou.com'
,
//扳手app
},
systemUrl
:
{
apiUrl
:
'https://system.banshouhui.com'
,
//java端域名请求头
}
}
module
.
exports
=
UNI_APP
;
.env.test.js
View file @
3342dd74
VUE_APP_ENV
=
"test"
\ No newline at end of file
const
UNI_APP
=
{
ucenterUrl
:
{
apiUrl
:
'https://rest-u.banshouhui.com'
,
//php端域名请求头
xueUrl
:
'https://xue.banshouhui.com'
,
//学院
banshou
:
'https://m.banshou.com'
,
//扳手app
},
systemUrl
:
{
apiUrl
:
'https://system.banshouhui.com'
,
//java端域名请求头
}
}
module
.
exports
=
UNI_APP
;
src/common/http.interceptor.js
View file @
3342dd74
...
...
@@ -22,8 +22,9 @@ const getSessionId = function(vm) {
}
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token
// 同时,我们也可以在此使用getApp().globalData,如果你把token放在getApp().globalData的话,也是可以使用的
import
globalUrl
from
'@/common/base_url.js'
// import globalUrl from '@/common/base_url.js'
const
globalUrl
=
process
.
uniEnv
||
{}
console
.
log
(
globalUrl
,
'globalUrl'
)
const
install
=
(
Vue
,
vm
)
=>
{
let
systemApiUrl
=
globalUrl
.
systemUrl
.
apiUrl
let
ucenterApiUrl
=
globalUrl
.
ucenterUrl
.
apiUrl
...
...
@@ -50,12 +51,13 @@ const install = (Vue, vm) => {
});
// 请求拦截,配置Token等参数
Vue
.
prototype
.
$u
.
http
.
interceptor
.
request
=
(
config
)
=>
{
debugger
const
reg
=
/
\?\w
+/
;
let
token
=
util
.
getToken
()
if
(
!
token
&&
noLoginUrl
.
indexOf
(
config
.
url
)
<
0
){
toLoginPage
()
return
false
}
//
if(!token && noLoginUrl.indexOf(config.url)<0){
//
toLoginPage()
//
return false
//
}
// // const token = app && app.globalData && app.globalData.token || ''
if
(
config
.
url
.
indexOf
(
'access-token='
)
>=
0
&&
config
.
params
[
'access-token'
]){
// 给默认参数增加access-token (Java端)
...
...
src/main.js
View file @
3342dd74
import
Vue
from
'vue'
import
App
from
'./App'
import
uView
from
"uview-ui"
;
import
vuexStore
from
"@/store/$u.mixin.js"
;
// let vuexStore = require('@/store/$u.mixin.js')
import
{
router
,
RouterMount
}
from
'@/router/index.js'
//路径换成自己的
Vue
.
config
.
productionTip
=
false
Vue
.
mixin
(
vuexStore
)
Vue
.
use
(
uView
);
App
.
mpType
=
'app'
const
app
=
new
Vue
({
...
App
})
...
...
src/store/$u.mixin.js
0 → 100644
View file @
3342dd74
import
{
mapState
}
from
'vuex'
import
store
from
"@/store/index"
console
.
log
(
store
,
'store'
)
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let
$uStoreKey
=
[];
try
{
$uStoreKey
=
store
.
state
?
Object
.
keys
(
store
.
state
)
:
[];
}
catch
(
e
){
}
module
.
exports
=
{
created
()
{
this
.
$u
.
vuex
=
(
name
,
value
)
=>
{
this
.
$store
.
commit
(
'$uStore'
,
{
name
,
value
})
}
},
computed
:
{
...
mapState
(
$uStoreKey
)
}
}
\ No newline at end of file
src/store/index.js
0 → 100644
View file @
3342dd74
import
Vue
from
'vue'
import
Vuex
from
'vuex'
Vue
.
use
(
Vuex
)
let
lifeData
=
{};
try
{
// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
lifeData
=
uni
.
getStorageSync
(
'lifeData'
);
}
catch
(
e
)
{
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let
saveStateKeys
=
[
'vuex_user'
,
'vuex_wx_uid'
,
'vuex_token'
,
'vuex_worktypeId'
];
// 保存变量到本地存储中
const
saveLifeData
=
function
(
key
,
value
)
{
// 判断变量名是否在需要存储的数组中
if
(
saveStateKeys
.
indexOf
(
key
)
!=
-
1
)
{
// 获取本地存储的lifeData对象,将变量添加到对象中
let
tmp
=
uni
.
getStorageSync
(
'lifeData'
);
// 第一次打开APP,不存在lifeData变量,故放一个{}空对象
tmp
=
tmp
?
tmp
:
{};
tmp
[
key
]
=
value
;
// 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中
uni
.
setStorageSync
(
'lifeData'
,
tmp
);
}
}
const
store
=
new
Vuex
.
Store
({
state
:
{
// 'dddd':'ds'
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
// vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {},
// vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
// vuex_isAdmin: lifeData.vuex_isAdmin ? lifeData.vuex_isAdmin : false,
// vuex_delete_article: false,
// vuex_delete_question: false,
// vuex_update_article: false,
// vuex_update_question: false,
// vuex_version: '1.0.1',
// vuex_config: {},
// vuex_bio: '这家伙很懒,什么也没写!',
// vuex_other_user:{},
// vuex_invitecode: lifeData.vuex_invitecode ? lifeData.vuex_invitecode : '', //邀请码
// vuex_wx_uid: lifeData.vuex_wx_uid || 0,
// vuex__token__: '',
// vuex_third:{},
// vuex_worktype:{
// list:[],
// active:0,
// },
// vuex_worktype_visible:false, //选择工种类型弹窗
// vuex_worktypeId:lifeData.vuex_worktypeId || 0,
// vuex_parse_style: {
// // 字符串的形式
// h1: 'padding:20rpx 0;',
// h2: 'padding:10rpx 0;',
// h3: 'padding:10rpx 0;',
// h4: 'padding:10rpx 0;',
// h5: 'padding:5rpx 0;',
// h6: 'padding:5rpx 0;',
// ul: 'margin-bottom:20rpx;padding-left:30rpx;',
// ol: 'margin-bottom:20rpx;padding-left:30rpx;',
// code: 'background-color: #f6f6f6;margin: 0 5rpx;padding: 6rpx 8rpx;border-radius: 6rpx;text-align:center;',
// pre: 'white-space: pre;overflow: auto;background: #f6f6f6;border-radius: 8rpx;border: none;color: #1a1a1a;margin-bottom: 20rpx;padding:20rpx;',
// 'pre code': 'margin:0;padding:0;',
// blockquote: 'padding: 15rpx;margin:0 0 20rpx 0;border-radius: 6rpx;',
// p: 'margin-bottom:20rpx',
// table: 'width:100%;margin-bottom:20rpx;border-collapse: collapse;',
// th: 'background-color: whitesmoke;border: 1px solid #e6e6e6;padding:10rpx;',
// td: 'border: 1px solid #e6e6e6;padding:10rpx;'
// },
},
mutations
:
{
$uStore
(
state
,
payload
)
{
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
let
nameArr
=
payload
.
name
.
split
(
'.'
);
let
saveKey
=
''
;
let
len
=
nameArr
.
length
;
if
(
len
>=
2
)
{
let
obj
=
state
[
nameArr
[
0
]];
for
(
let
i
=
1
;
i
<
len
-
1
;
i
++
)
{
obj
=
obj
[
nameArr
[
i
]];
}
obj
[
nameArr
[
len
-
1
]]
=
payload
.
value
;
saveKey
=
nameArr
[
0
];
}
else
{
// 单层级变量,在state就是一个普通变量的情况
state
[
payload
.
name
]
=
payload
.
value
;
saveKey
=
payload
.
name
;
}
// 保存变量到本地,见顶部函数定义
saveLifeData
(
saveKey
,
state
[
saveKey
])
}
}
})
console
.
log
(
store
,
'store----------------'
)
export
default
store
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