Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MiniprogramTemplate
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
谢卓城
MiniprogramTemplate
Commits
0d8c2cd3
Commit
0d8c2cd3
authored
Jan 25, 2021
by
谢卓城
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增:自定义导航组件navigationbar
parent
5609ea90
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
157 additions
and
42 deletions
+157
-42
index.js
.template/components/Test/index.js
+2
-1
index.js
.template/components/index/index.js
+2
-1
app.js
src/app.js
+62
-5
home-header.js
src/components/home-header/home-header.js
+0
-24
home-header.scss
src/components/home-header/home-header.scss
+0
-6
home-header.wxml
src/components/home-header/home-header.wxml
+0
-4
index.js
src/components/navigationbar/index.js
+65
-0
index.json
src/components/navigationbar/index.json
+0
-0
index.scss
src/components/navigationbar/index.scss
+11
-0
index.wxml
src/components/navigationbar/index.wxml
+9
-0
index.json
src/pages/index/index.json
+3
-1
index.wxml
src/pages/index/index.wxml
+3
-0
No files found.
.template/components/Test/index.js
View file @
0d8c2cd3
...
@@ -17,7 +17,8 @@ Component({
...
@@ -17,7 +17,8 @@ Component({
methods
:
{
methods
:
{
// 这里是一个自定义方法
// 这里是一个自定义方法
tagAction
(
e
)
{
tagAction
(
e
)
{
var
eventOption
=
{
content
:
e
.
currentTarget
.
dataset
.
text
};
// 触发事件的选项
console
.
log
(
e
);
var
eventOption
=
{
};
// 触发事件的选项
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
}
}
}
}
...
...
.template/components/index/index.js
View file @
0d8c2cd3
...
@@ -17,7 +17,8 @@ Component({
...
@@ -17,7 +17,8 @@ Component({
methods
:
{
methods
:
{
// 这里是一个自定义方法
// 这里是一个自定义方法
tagAction
(
e
)
{
tagAction
(
e
)
{
var
eventOption
=
{
content
:
e
.
currentTarget
.
dataset
.
text
};
// 触发事件的选项
console
.
log
(
e
);
var
eventOption
=
{
};
// 触发事件的选项
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
}
}
}
}
...
...
src/app.js
View file @
0d8c2cd3
...
@@ -5,11 +5,10 @@ App({
...
@@ -5,11 +5,10 @@ App({
onLaunch
:
function
()
{
onLaunch
:
function
()
{
// 初始化axios
// 初始化axios
Request
.
initAxios
();
Request
.
initAxios
();
// 展示本地存储能力
var
logs
=
wx
.
getStorageSync
(
"logs"
)
||
[];
logs
.
unshift
(
Date
.
now
());
wx
.
setStorageSync
(
"logs"
,
logs
);
// 获取设备信息并保存
this
.
saveData
();
// 登录
// 登录
wx
.
login
({
wx
.
login
({
success
:
res
=>
{
success
:
res
=>
{
...
@@ -37,7 +36,65 @@ App({
...
@@ -37,7 +36,65 @@ App({
}
}
});
});
},
},
saveData
()
{
// 取得设备信息
try
{
// const res = wx.getSystemInfoSync()
const
that
=
this
wx
.
getSystemInfo
({
success
(
res
)
{
// 根据不同的手机算出状态栏的高度
let
custom
=
null
try
{
custom
=
wx
.
getMenuButtonBoundingClientRect
()
that
.
globalData
.
devicePixelRatio
=
res
.
devicePixelRatio
that
.
globalData
.
statusBarHeight
=
res
.
statusBarHeight
that
.
globalData
.
customBarHeight
=
custom
.
bottom
+
custom
.
top
-
res
.
statusBarHeight
that
.
globalData
.
menuBotton
=
custom
.
top
-
res
.
statusBarHeight
,
that
.
globalData
.
menuRight
=
res
.
screenWidth
-
custom
.
right
,
// 胶囊距右方间距(方保持左、右间距一致)
that
.
globalData
.
menuHeight
=
custom
.
height
// 胶囊高度(自定义内容可与胶囊高度保证一致)
that
.
globalData
.
menuBottonTop
=
custom
.
top
+
(
custom
.
height
-
32
)
/
2
}
catch
(
e
)
{
that
.
globalData
.
devicePixelRatio
=
1
//res.devicePixelRatio
that
.
globalData
.
statusBarHeight
=
20
//res.statusBarHeight
that
.
globalData
.
customBarHeight
=
60
//res.statusBarHeight
}
if
(
res
.
screenHeight
/
res
.
screenWidth
>
2
&&
res
.
platform
==
"android"
)
{
that
.
globalData
.
isIphoneX
=
true
}
// console.log('手机信息res' + res.model.search('iPhone X'))
let
modelmes
=
res
.
model
if
(
modelmes
.
search
(
'iPhone X'
)
!=
-
1
||
modelmes
.
search
(
'iPhone XR'
)
!=
-
1
)
{
that
.
globalData
.
isIphoneX
=
true
}
console
.
log
(
res
.
screenHeight
,
res
.
screenWidth
,
res
,
'screenWidth'
)
// console.log(res)
if
(
opts
.
query
.
channel
&&
opts
.
query
.
channel
!==
''
)
that
.
globalData
.
channel
=
opts
.
query
.
channel
// console.log(that.globalData.channel)
that
.
globalData
.
uuid
=
util
.
guid
()
wx
.
setStorageSync
(
'uuid'
,
that
.
globalData
.
uuid
)
wx
.
setStorageSync
(
'systemInfo'
,
JSON
.
stringify
(
res
))
}
})
}
catch
(
e
)
{
// Do something when catch error
}
},
globalData
:
{
globalData
:
{
userInfo
:
null
userInfo
:
null
,
isIphoneX
:
false
,
menuBottonTop
:
0
,
devicePixelRatio
:
1
,
statusBarHeight
:
20
,
customBarHeight
:
60
,
menuBotton
:
0
,
menuRight
:
0
,
// 胶囊距右方间距(方保持左、右间距一致)
menuHeight
:
0
}
}
});
});
src/components/home-header/home-header.js
deleted
100644 → 0
View file @
5609ea90
/**
* 除继承样式外, app.wxss 中的样式、组件所在页面的的样式对自定义组件无效。
* 参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
* 采用 externalClasses 的方式 在组件.wxml需要的view的class加super-class,可以是多个
* 使用 <Component super-class="<#type#>" />
*/
Component
({
properties
:
{
is
:
Boolean
,
list
:
Array
,
title
:
String
// 简化的定义方式
},
externalClasses
:
[
"super-class"
],
data
:
{
content
:
"content"
},
methods
:
{
// 这里是一个自定义方法
tagAction
(
e
)
{
var
eventOption
=
{
content
:
e
.
currentTarget
.
dataset
.
text
};
// 触发事件的选项
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
}
}
});
src/components/home-header/home-header.scss
deleted
100644 → 0
View file @
5609ea90
.container
{
width
:
100vw
;
.text
{
color
:
red
;
}
}
\ No newline at end of file
src/components/home-header/home-header.wxml
deleted
100644 → 0
View file @
5609ea90
<!--template/components/index.wxml-->
<view class="container" hover-class="none" hover-stop-propagation="false">
<text class="flex-item super-class" selectable="false" space="false" decode="false" bindtap="tagAction" data-text="{{content}}">{{content}}</text>
</view>
src/components/navigationbar/index.js
0 → 100644
View file @
0d8c2cd3
/**
* 除继承样式外, app.wxss 中的样式、组件所在页面的的样式对自定义组件无效。
* 参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
* 采用 externalClasses 的方式 在组件.wxml需要的view的class加super-class,可以是多个
* 使用 <Component super-class="<#type#>" />
*/
let
app
=
getApp
();
Component
({
properties
:
{
title
:
String
,
titleColor
:
String
,
leftIcon
:
String
,
titleOpcity
:
{
type
:
Number
,
value
:
1
},
opcity
:
{
type
:
Number
,
value
:
0
},
iconOpcity
:
{
type
:
Number
,
value
:
0
}
},
externalClasses
:
[
"super-class"
],
data
:
{
navBar
:
0
,
statusBarHeight
:
app
.
globalData
.
statusBarHeight
,
navBarHeight
:
0
,
// 导航栏高度 = navBar + 状态栏高度
menuBotton
:
0
,
// 胶囊距底部间距(保持底部间距一致)
menuRight
:
0
,
// 胶囊距右方间距(方保持左、右间距一致)
menuHeight
:
0
// 胶囊高度(自定义内容可与胶囊高度保证一致)
},
pageLifetimes
:
{
// 组件所在页面的生命周期函数
show
:
function
()
{
this
.
setNavBarInfo
();
}
},
methods
:
{
/**
* @description 设置导航栏信息
*/
setNavBarInfo
()
{
this
.
setData
({
menuBotton
:
app
.
globalData
.
menuBotton
,
menuRight
:
app
.
globalData
.
menuRight
,
// 胶囊距右方间距(方保持左、右间距一致)
menuHeight
:
app
.
globalData
.
menuHeight
,
// 胶囊高度(自定义内容可与胶囊高度保证一致)
navBar
:
app
.
globalData
.
customBarHeight
-
app
.
globalData
.
statusBarHeight
,
navBarHeight
:
app
.
globalData
.
customBarHeight
,
top
:
app
.
globalData
.
menuBottonTop
});
},
// 这里是一个自定义方法
tagAction
(
e
)
{
console
.
log
(
e
);
var
eventOption
=
{
};
// 触发事件的选项
this
.
triggerEvent
(
"tagClick"
,
eventOption
);
}
}
});
src/components/
home-header/home-header
.json
→
src/components/
navigationbar/index
.json
View file @
0d8c2cd3
File moved
src/components/navigationbar/index.scss
0 → 100644
View file @
0d8c2cd3
.container
{
width
:
100vw
;
position
:
fixed
;
left
:
0
;
top
:
0
;
z-index
:
9998
;
.header-view
{
text-align
:
center
;
}
}
\ No newline at end of file
src/components/navigationbar/index.wxml
0 → 100644
View file @
0d8c2cd3
<!--template/components/index.wxml-->
<view class="container" hover-class="none" hover-stop-propagation="false" style="height:{{navBarHeight}}px; background:rgba(255,255,255,{{opcity}});">
<view class="header-view"
style="padding-top:{{statusBarHeight}}px; opacity:{{titleOpcity}}; box-sizing:unset; color:{{titleColor}}; height:{{navBar}}px; line-height:{{navBar}}px;">{{title}}</view>
<view class="left-header-icon" style="margin-top:{{top}}px" wx:if="{{leftIcon}}">
<image class="left-icon" src="{{leftIcon}}" size="32" color="{{opcity>=1?'#000':'#fff'}}" bindtap="tagAction" style="background:rgba(33, 33, 33, {{iconOpcity}});" />
</view>
</view>
src/pages/index/index.json
View file @
0d8c2cd3
{
{
"navigationBarTitleText"
:
"首页"
,
"navigationBarTitleText"
:
"首页"
,
"navigationStyle"
:
"custom"
,
"navigationStyle"
:
"custom"
,
"usingComponents"
:
{}
"usingComponents"
:
{
"NavigationBar"
:
"../../components/navigationbar/index"
}
}
}
src/pages/index/index.wxml
View file @
0d8c2cd3
<!--index.wxml-->
<!--index.wxml-->
<view class="container">
<view class="container">
<NavigationBar title="首界面" opcity="{{1}}" />
<view class="userinfo">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<block wx:else>
...
...
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