Commit 65dd59d4 authored by 谢卓城's avatar 谢卓城

完善:1.共用样式. 2.共用模板

parent 5a7525d0
...@@ -7,23 +7,24 @@ ...@@ -7,23 +7,24 @@
*/ */
Component({ Component({
properties: { properties: {
is: Boolean, //是否可见
list: Array, visible: {
title: String // 简化的定义方式 type: Boolean,
value: true
},
}, },
options: { options: {
styleIsolation: 'apply-shared' styleIsolation: 'apply-shared'
}, },
externalClasses: [], options: {
data: { multipleSlots: true // 在组件定义时的选项中启用多slot支持
content: "content"
}, },
externalClasses: ["custom-class"],
data: {},
methods: { methods: {
// 这里是一个自定义方法 // 这里是一个自定义方法
tagAction(e) { tagAction(e) {
console.log(e); this.triggerEvent("tagClick", e);
var eventOption = { }; // 触发事件的选项
this.triggerEvent("tagClick", eventOption);
} }
} }
}); });
.container {
width: 100vw;
.text {
color: red;
}
}
\ No newline at end of file
<!--template/components/index.wxml--> <!--template/components/index.wxml-->
<view class="container" hover-class="none" hover-stop-propagation="false"> <view class="container" hover-class="none" wx:if="{{visible}}">
<text class="flex-item super-class" selectable="false" space="false" decode="false" bindtap="tagAction" data-text="{{content}}">{{content}}</text> <text class="super-class" selectable="false" space="false" decode="false" bindtap="tagAction">xxxxx</text>
</view> </view>
...@@ -7,23 +7,21 @@ ...@@ -7,23 +7,21 @@
*/ */
Component({ Component({
properties: { properties: {
is: Boolean, //是否可见
list: Array, visible: {
title: String // 简化的定义方式 type: Boolean,
value: true
},
}, },
options: { options: {
styleIsolation: 'apply-shared' styleIsolation: 'apply-shared'
}, },
externalClasses: ["super-class"], externalClasses: ["custom-class"],
data: { data: {},
content: "content"
},
methods: { methods: {
// 这里是一个自定义方法 // 这里是一个自定义方法
tagAction(e) { tagAction(e) {
console.log(e); this.triggerEvent("tagClick", e);
var eventOption = { }; // 触发事件的选项
this.triggerEvent("tagClick", eventOption);
} }
} }
}); });
.container {
width: 100vw;
.text {
color: red;
}
}
\ No newline at end of file
<!--template/components/index.wxml--> <!--template/components/index.wxml-->
<view class="container" hover-class="none" hover-stop-propagation="false"> <view class="container" wx:if="{{visible}}">
<text class="flex-item super-class" selectable="false" space="false" decode="false" bindtap="tagAction" data-text="{{content}}">{{content}}</text> <text class="custom-class" selectable="false" space="false" decode="false" bindtap="tagAction">xxxxxx</text>
</view> </view>
...@@ -4,10 +4,10 @@ const { axiosPost, axiosGet } = require("../utils/request.js"); ...@@ -4,10 +4,10 @@ const { axiosPost, axiosGet } = require("../utils/request.js");
* test * test
* @returns {*|Promise|Promise<unknown>} * @returns {*|Promise|Promise<unknown>}
*/ */
const postTest = params => { const postTest = (params) => {
return axiosPost({ return axiosPost({
url: "page/test", url: "page/test",
data: params data: params,
}); });
}; };
...@@ -17,10 +17,10 @@ const postTest = params => { ...@@ -17,10 +17,10 @@ const postTest = params => {
*/ */
const getData = () => { const getData = () => {
return axiosGet({ return axiosGet({
url: "/shakespeare/notes/28193853/user_notes" url: "/shakespeare/notes/28193853/user_notes",
}); });
}; };
module.exports = { module.exports = {
getData getData,
}; };
\ No newline at end of file
//app.js //app.js
const Request = require("./utils/request.js"); const Request = require("./utils/request.js");
/**
* tabBar页面路径列表 (用于链接跳转时判断)
* tabBarLinks为常量, 无需修改
*/
const tabBarLinks = ["pages/index/index"];
App({ App({
// 处理无效页面 // 处理无效页面
onPageNotFound(res) { onPageNotFound(res) {
...@@ -16,32 +22,8 @@ App({ ...@@ -16,32 +22,8 @@ App({
// 获取设备信息并保存 // 获取设备信息并保存
this.saveData(); this.saveData();
// 登录 // 小程序主动更新
wx.login({ this.updateManager();
success: (res) => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
},
});
// 获取用户信息
wx.getSetting({
success: (res) => {
if (res.authSetting["scope.userInfo"]) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: (res) => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo;
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res);
}
},
});
}
},
});
}, },
saveData() { saveData() {
// 取得设备信息 // 取得设备信息
...@@ -101,6 +83,82 @@ App({ ...@@ -101,6 +83,82 @@ App({
// Do something when catch error // Do something when catch error
} }
}, },
/**
* 获取tabBar页面路径列表
*/
getTabBarLinks: function () {
return tabBarLinks;
},
/**
* 跳转到指定页面,检查登录情况
* 支持tabBar页面
*/
checkLoginNavigationTo: function (url, callback) {
if (this.globalData.userInfo == null) {
url = "/pages/login/login";
}
this.navigationTo(url, callback);
},
/**
* 跳转到指定页面
* 支持tabBar页面
*/
navigationTo: function (url, callback) {
if (!url || url.length == 0) {
return false;
}
let tabBarLinks = this.getTabBarLinks();
// tabBar页面
if (tabBarLinks.indexOf(url) > -1) {
wx.switchTab({
url: url,
});
} else {
console.log("navigationTo =======" + url);
// 普通页面
wx.navigateTo({
url: url,
});
}
if (callback && typeof callback === "function") {
this.checkLoginCallback = callback;
}
},
// 更新
updateManager() {
if (!wx.canIUse("getUpdateManager")) {
Tip.toast("当前微信版本过低,无法使用自动更新功能,请升级到最新微信版本");
return false;
}
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
console.log("新版本更新");
}
});
updateManager.onUpdateReady(function () {
wx.showModal({
title: "更新提示",
content: "新版本已经准备好,即将重启应用",
showCancel: false,
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: "更新提示",
content: "新版本下载失败",
showCancel: false,
});
});
},
globalData: { globalData: {
userInfo: null, userInfo: null,
isIphoneX: false, isIphoneX: false,
......
@import './style.scss'; @import './style.scss';
$colors: ( $colors: (
"themeColor": #8FBC8F, "red": #f94f50,
"white": #fff,
"black": #282828,
); );
$tc: map-get($colors, 'themeColor'); @each $colorKey, $color in $colors {
.text-#{$colorKey} {
color: $color !important;
}
.bg-#{$colorKey} {
background-color: $color !important;
}
}
@mixin width($value: 100%) { @mixin width($value: 100%) {
width: $value; width: $value;
...@@ -14,6 +22,39 @@ $tc: map-get($colors, 'themeColor'); ...@@ -14,6 +22,39 @@ $tc: map-get($colors, 'themeColor');
height: $value; height: $value;
} }
@mixin line($line: 0) {
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
white-space: normal !important;
-webkit-line-clamp: $line;
-webkit-box-orient: vertical;
display: -webkit-box;
word-break: break-all;
}
@mixin font($size: 0) {
font-size: ($size*2);
}
.line-four {
@include line(4);
}
.line-three {
@include line(3);
}
// 限制两行文字
.line-two {
@include line(2);
}
// 限制一行文字
.line-one {
@include line(1);
}
// width, height // width, height
.w-100 { .w-100 {
@include width(); @include width();
......
...@@ -28,4 +28,19 @@ ...@@ -28,4 +28,19 @@
} }
.flex-wrap { .flex-wrap {
flex-wrap: wrap; flex-wrap: wrap;
}
.relative {
position: relative;
}
// 文字删除线
.delete-line{
color: #9b9b9b;
text-decoration: line-through;
text-decoration-color: #9b9b9b;
}
.open-type-button[plain] {
border: 0;
display: inline;
} }
\ No newline at end of file
// copy changein -> common/scss/_variables // copy changein -> common/scss/_variables
$base-font-size: 26rpx; $fonts: (
20,
$font-sizes: ( 22,
xxs: 0.6923, 24,
// 18rpx 26,
xs: 0.7692, 28,
// 20rpx 30,
ssm: 0.8462, 32,
// 22rpx 34,
sm: 0.9230, 36,
// 24rpx 38,
md: 1, 40,
// 26rpx
lg: 1.0769,
// 28rpx
xl: 1.1538,
// 30rpx
); );
// 字体
@each $size in $fonts {
.fs-#{$size} {
font-size: $size * 1rpx;
}
}
// spacing // spacing
// 0-5: 0 // 0-5: 0
// .mt-1 => margin top .pb-2 // .mt-1 => margin top .pb-2
...@@ -26,18 +28,53 @@ $spacing-types: ( ...@@ -26,18 +28,53 @@ $spacing-types: (
m: margin, m: margin,
p: padding, p: padding,
); );
$spacing-directions: ( $spacing-directions: (
t: top, t: top,
r: right, r: right,
b: bottom, b: bottom,
l: left, l: left,
); );
$spacing-base-size: 1rpx;
$spacing-sizes: (
0,
10,
20,
30,
40,
50,
60,
70,
80,
90,
100,
);
// m-0, mx-0
@each $sizeKey, $size in $font-sizes { @each $typeKey, $type in $spacing-types {
.fs-#{$sizeKey} { // .m-10
font-size: $size * $base-font-size; @each $size in $spacing-sizes {
.#{$typeKey}-#{$size} {
#{$type}: $size * $spacing-base-size;
}
}
// .mx-10 , .my-10
@each $size in $spacing-sizes {
.#{$typeKey}x-#{$size} {
#{$type}-left: $size * $spacing-base-size;
#{$type}-right: $size * $spacing-base-size;
}
.#{$typeKey}y-#{$size} {
#{$type}-top: $size * $spacing-base-size;
#{$type}-bottom: $size * $spacing-base-size;
}
}
// .mt-10
@each $directionKey, $direction in $spacing-directions {
@each $size in $spacing-sizes {
.#{$typeKey}#{$directionKey}-#{$size} {
#{$type}-#{$direction}: $size * $spacing-base-size;
}
}
} }
} }
...@@ -65,13 +102,13 @@ $flex-align-items: ( ...@@ -65,13 +102,13 @@ $flex-align-items: (
); );
@each $key, $value in $flex-justify-content { @each $key, $value in $flex-justify-content {
.justify-#{$key} { .flex-justify-#{$key} {
justify-content: $value; justify-content: $value;
} }
} }
@each $key, $value in $flex-align-items { @each $key, $value in $flex-align-items {
.align-#{$key} { .flex-align-#{$key} {
align-items: $value; align-items: $value;
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ Component({ ...@@ -11,6 +11,7 @@ Component({
properties: { properties: {
title: String, title: String,
titleColor: String, titleColor: String,
showLeftIcon: Boolean,
leftIcon: String, leftIcon: String,
titleOpcity: { titleOpcity: {
type: Number, type: Number,
...@@ -24,8 +25,12 @@ Component({ ...@@ -24,8 +25,12 @@ Component({
type: Number, type: Number,
value: 0, value: 0,
}, },
fixed: {
type: Boolean,
value: true,
},
backgroundColor: String,
}, },
externalClasses: ["super-class"],
data: { data: {
navBar: 0, navBar: 0,
statusBarHeight: app.globalData.statusBarHeight, statusBarHeight: app.globalData.statusBarHeight,
...@@ -51,14 +56,17 @@ Component({ ...@@ -51,14 +56,17 @@ Component({
menuHeight: app.globalData.menuHeight, // 胶囊高度(自定义内容可与胶囊高度保证一致) menuHeight: app.globalData.menuHeight, // 胶囊高度(自定义内容可与胶囊高度保证一致)
navBar: app.globalData.customBarHeight - app.globalData.statusBarHeight, navBar: app.globalData.customBarHeight - app.globalData.statusBarHeight,
navBarHeight: app.globalData.customBarHeight, navBarHeight: app.globalData.customBarHeight,
top: app.globalData.menuBottonTop, top: app.globalData.top,
}); });
}, },
// 这里是一个自定义方法 // 这里是一个自定义方法
tagAction(e) { back(e) {
console.log(e); this.triggerEvent("back", {});
var eventOption = {}; // 触发事件的选项 },
this.triggerEvent("tagClick", eventOption); backHome(e) {
wx.switchTab({
url: "/pages/index/index",
});
}, },
}, },
}); });
.container { .navigationbar-container {
width: 100vw; width: 100vw;
position: fixed; position: fixed;
left: 0; left: 0;
...@@ -8,4 +8,10 @@ ...@@ -8,4 +8,10 @@
.header-view { .header-view {
text-align: center; text-align: center;
} }
.left-header-icon {
position: absolute;
.icon {
margin-left: 29rpx;
}
}
} }
\ No newline at end of file
<!--template/components/index.wxml--> <!--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="navigationbar-container" hover-class="none" hover-stop-propagation="false" >
<view class="header-view" <view class="navigationbar" hover-class="none"
style="padding-top:{{statusBarHeight}}px; opacity:{{titleOpcity}}; box-sizing:unset; color:{{titleColor}}; height:{{navBar}}px; line-height:{{navBar}}px;">{{title}}</view> style="height:{{navBarHeight}}px; background:{{backgroundColor}};">
<view class="left-header-icon" style="margin-top:{{top}}px" wx:if="{{leftIcon}}"> <view class="header-view"
<image class="left-icon" src="{{leftIcon}}" size="32" color="{{opcity>=1?'#000':'#fff'}}" bindtap="tagAction" style="background:rgba(33, 33, 33, {{iconOpcity}});" /> style="padding-top:{{statusBarHeight}}px; opacity:{{titleOpcity}}; box-sizing:unset; color:{{titleColor}}; height:{{navBar}}px; line-height:{{navBar}}px;">{{title}}</view>
</view> <view class="left-header-icon"
style="margin-left:{{menuRight}}px; top:{{statusBarHeight+navBar/2-12}}px;" wx:if="{{showLeftIcon}}" >
<van-icon name="arrow-left" color="{{opcity>=1?'#000':'#fff'}}" size="24px" bind:click="back"/>
<!-- <image class="icon" style="color:{{opcity>=1?'#000':'#fff'}};" src="../../assets/images/index/back_home.png" lazy-load="false" binderror="" /> -->
<van-icon name="wap-home-o" custom-class="icon" color="{{opcity>=1?'#000':'#fff'}}" size="24px" bind:click="backHome"/>
</view>
</view>
<view class="" style="height:{{fixed?0:navBarHeight*2}}rpx;"/>
</view> </view>
export const EMPLOYEE_STATUS = { export const EMPLOYEE_STATUS = {
NORMAL: { NORMAL: {
value: 1, value: 1,
desc: '正常' desc: "正常",
}, },
DISABLED: { DISABLED: {
value: 1, value: 1,
desc: '禁用' desc: "禁用",
}, },
DELETED: { DELETED: {
value: 2, value: 2,
desc: '已删除' desc: "已删除",
} },
}; };
export default { export default {
EMPLOYEE_STATUS EMPLOYEE_STATUS,
}; };
\ No newline at end of file
.container { .container {
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
}
.usermotto { .usermotto {
text-align: center; text-align: center;
margin-top: 200px; margin-top: 200px;
......
<!--index.wxml--> <!--index.wxml-->
<view class="container"> <view class="container">
<NavigationBar title="首界面" opcity="{{1}}" /> <NavigationBar title="首" opcity="{{1}}" />
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto"> <view class="usermotto">
<button bind:tap="requestAction"> 网络请求 </button> <button bind:tap="requestAction"> 网络请求 </button>
</view> </view>
......
const formatTime = date => { const formatTime = (date) => {
const year = date.getFullYear(); const year = date.getFullYear();
const month = date.getMonth() + 1; const month = date.getMonth() + 1;
const day = date.getDate(); const day = date.getDate();
...@@ -9,11 +9,11 @@ const formatTime = date => { ...@@ -9,11 +9,11 @@ const formatTime = date => {
return time + " " + [hour, minute, second].map(formatNumber).join(":"); return time + " " + [hour, minute, second].map(formatNumber).join(":");
}; };
const formatNumber = n => { const formatNumber = (n) => {
n = n.toString(); n = n.toString();
return n[1] ? n : "0" + n; return n[1] ? n : "0" + n;
}; };
module.exports = { module.exports = {
formatTime: formatTime formatTime,
}; };
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