Browse Source

封装 format.wxs文件

dongyuan0658 6 years ago
parent
commit
04d34eaaa2

+ 24 - 0
pages/commonWxs/format.wxs

@@ -0,0 +1,24 @@
+function formatDate(time) {
+  var t = getDate(time);
+  var tf = function (i) { return (i < 10 ? '0' : '') + i };
+  var year = t.getFullYear();
+  var month = tf(t.getMonth() + 1);
+  var day = tf(t.getDate());
+  var hour = tf(t.getHours());
+  var minute = tf(t.getMinutes());
+  return month + '-' + day + ' ' + hour + ':' + minute;
+}
+
+function getBirthday(birthday) {
+  var t = getDate(birthday);
+  var tf = function (i) { return (i < 10 ? '0' : '') + i };
+  var year = t.getFullYear();
+  var month = tf(t.getMonth() + 1);
+  var day = tf(t.getDate());
+  return year + '年' + month + '月' + day + '日';
+}
+
+module.exports = {
+  formatDate: formatDate,
+  getBirthday: getBirthday
+}

+ 2 - 15
pages/user/myconcern/myconcern.wxml

@@ -1,17 +1,4 @@
-<wxs module="wxs">
-  function formatDate(time) {
-    console.log(time);
-    var t = getDate(time); 
-    var tf = function(i){return (i < 10 ? '0' : '') + i};
-    var year = t.getFullYear();
-    var month = tf(t.getMonth() + 1);
-    var day = tf(t.getDate());
-    var hour = tf(t.getHours());
-    var minute = tf(t.getMinutes());
-    return month + '-' + day + ' ' + hour + ':' + minute;
-  }
-  module.exports.formatDate = formatDate;
-</wxs>
+<wxs src="../../commonWxs/format.wxs" module="format" />
 <view class='my-concern'>
   <view class="concern-center">
     <view class='concern-info' wx:for="{{ fanList }}" wx:key="{{ index }}" bindtap='toUserDetails' data-uid='{{ item.user.uid }}' data-fanId='{{ item.fans.fanId }}'>
@@ -20,7 +7,7 @@
       </view>
       <view class="avatar-name">
         <text class="nickName">{{ item.user.wechatName }}</text>
-        <text class="time">{{ wxs.formatDate(item.fans.gmtCreated) }}</text>
+        <text class="time">{{ format.formatDate(item.fans.gmtCreated) }}</text>
       </view>
       <view class="avatar-follow" wx:if='{{ item.isEachOther }}'>
         <view class='avatar-img'>

+ 1 - 8
pages/user/myread/myread.wxml

@@ -1,11 +1,4 @@
-<wxs module="wxs">
-  function formatDate(time) {
-    var timeTemp = getDate(time);
-    var timeString = timeTemp.toLocaleDateString() + timeTemp.toLocaleTimeString();
-    return timeString.replace('/','-').replace('/','-').replace('上午',' ').replace('下午',' ');
-  }
-  module.exports.formatDate = formatDate;
-</wxs>
+<wxs src="../../commonWxs/format.wxs" module="format" />
 <view class='my-read'>
   <view class='read-article' wx:for="{{ wareCards }}" wx:key="{{ index }}" bindtap='toWork' data-lessonId='{{ item.id }}' data-title='{{ item.title }}'>
     <view class='video-preview'>

+ 3 - 24
pages/user/myworks/myworks.wxml

@@ -1,26 +1,5 @@
 <!--pages/user/myworks/myworks.wxml-->
-<wxs module="wxs">
-  function formatDate(time) {
-    var t = getDate(time); 
-    var tf = function(i){return (i < 10 ? '0' : '') + i};
-    var year = t.getFullYear();
-    var month = tf(t.getMonth() + 1);
-    var day = tf(t.getDate());
-    var hour = tf(t.getHours());
-    var minute = tf(t.getMinutes());
-    return month + '-' + day + ' ' + hour + ':' + minute;
-  }
-  function getBirthday(birthday){
-    var t = getDate(birthday); 
-    var tf = function(i){return (i < 10 ? '0' : '') + i};
-    var year = t.getFullYear();
-    var month = tf(t.getMonth() + 1);
-    var day = tf(t.getDate());
-    return year + '年' + month + '月' + day + '日';
-  }
-  module.exports.formatDate = formatDate;
-  module.exports.getBirthday = getBirthday;
-</wxs>
+<wxs src="../../commonWxs/format.wxs" module="format" />
 <view class='user-works'>
   <view class='follow-details'>
     <view class='follow-info'>
@@ -41,7 +20,7 @@
           </view>
           <view wx:else class='gender-size'>未知</view>
         </view>
-        <view class='avatar-birthday'>{{ wxs.getBirthday(wareCards.user.birthday) }}</view>
+        <view class='avatar-birthday'>{{ format.getBirthday(wareCards.user.birthday) }}</view>
         <view class='avatar-address'>{{ wareCards.user.schoolName }}</view>
       </view>
     </view>
@@ -100,7 +79,7 @@
           </view>
         </view>
         <view class='user-name'>
-          <view class='left-detail'>{{ wxs.formatDate(item.userRead.gmtCreated) || 0 }}</view>
+          <view class='left-detail'>{{ format.formatDate(item.userRead.gmtCreated) || 0 }}</view>
           <view class='right-detail'>
             <view class='point-img'>
               <image src='../../../static/image/like.png'></image>

+ 4 - 15
pages/user/walletDetails/walletDetails.wxml

@@ -1,15 +1,4 @@
-<wxs module="wxs">
-  function formatDate(time) {
-    var timeTemp = getDate(time);
-    var timeString = timeTemp.toLocaleDateString() + timeTemp.toLocaleTimeString();
-    return timeString.replace('/','-').replace('/','-').replace('上午',' ').replace('下午',' ');
-  }
-  function parseDouble(number) {
-    return parseFloat(number).toFixed(2);
-  }
-  module.exports.formatDate = formatDate;
-  module.exports.parseDouble = parseDouble;
-</wxs>
+<wxs src="../../commonWxs/format.wxs" module="format" />
 <view class='walletDetails'>
   <view class="walletDetails-center">
     <view class='walletDetails-info' wx:for="{{ walletDatails }}" wx:key="{{ index }}">
@@ -20,17 +9,17 @@
         <view class="avatar-info">
           <text class="avatar-doc">{{ item.description }}</text>
 
-          <text class="avatar-time">{{wxs.formatDate(item.gmtCreated)}}</text>
+          <text class="avatar-time">{{format.formatDate(item.gmtCreated)}}</text>
         </view>
       </view>
       <view class="walletDetails-right">
         <view class="avatar-value-pos" wx:if="{{ item.type === 'INCOME' }}">
           <text class="avatar-symbol">+</text>
-          <text>{{ wxs.parseDouble(item.price / 100) }}</text>
+          <text>{{ format.parseDouble(item.price / 100) }}</text>
         </view>
         <view class="avatar-value-neg" wx:else>
           <text class="avatar-symbol">-</text>
-          <text>{{ wxs.parseDouble(item.price / 100) }}</text>
+          <text>{{ format.parseDouble(item.price / 100) }}</text>
         </view>
       </view>
     </view>