lanxin 1 週間 前
コミット
c0114346c4
3 ファイル変更38 行追加24 行削除
  1. 29 17
      pages/work/index.js
  2. 4 4
      pages/work/index.wxml
  3. 5 3
      pages/work/index.wxss

+ 29 - 17
pages/work/index.js

@@ -59,11 +59,12 @@ VueLikePage([], {
     years: [], // 年份数组
     months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], // 月份数组
     days: [], // 日期数组(根据年月动态生成)
-    selectedDate: '' // 最终选中的日期
+    selectedDates: [],
+    date:''
   },
   methods: {
     selectConfirm(e){
-      this.confirmIp()
+      this.confirmIp(e)
       // 拿到item,从confirmedIps去掉当前item
       const selectedItem = e.currentTarget.dataset.item
       console.log(selectedItem)
@@ -76,15 +77,16 @@ VueLikePage([], {
         rgb: selectedItem.rgb,
         imgUrl:selectedItem.typeIndex==1? selectedItem?.imgUrl:'',
         title: selectedItem.typeIndex==2?selectedItem?.title:'',
-        date: selectedItem.typeIndex==3?selectedItem?.date:'',
+        date: selectedItem.typeIndex==3?selectedItem?.date:this.data.date,
         ipScaleX: selectedItem.scaleX,
         ipScaleY: selectedItem.scaleY,
         ipRotate: selectedItem.rotate,
         ipLeft: selectedItem.left,
         ipTop: selectedItem.top,
-        positionInitialized:true
+        positionInitialized:true,
+        pickerValue:selectedItem.date.split('-').map(Number).map((v, i) => v - [2016, 1, 1][i])
       })
-      // console.log(this.data)
+      console.log(this.data)
     },
     loadDate() {
       const now = new Date();
@@ -111,7 +113,8 @@ VueLikePage([], {
       // 设置默认选中值
       this.setData({
         pickerValue: [yearIndex, monthIndex, currentDay - 1],
-        selectedDate: `${currentYear}-${this.formatNum(currentMonth)}-${this.formatNum(currentDay)}`
+        selectedDates:[ `${currentYear}-${this.formatNum(currentMonth)}-${this.formatNum(currentDay)}`],
+        date:`${currentYear}-${this.formatNum(currentMonth)}-${this.formatNum(currentDay)}`
       });
     },
 
@@ -135,6 +138,8 @@ VueLikePage([], {
 
     // 日期选择器滚动变化时触发
     onDateChange(e) {
+     
+      // this.selectIp(e)
       const [yearIndex, monthIndex, dayIndex] = e.detail.value;
       const {
         years,
@@ -154,8 +159,10 @@ VueLikePage([], {
       const newDayIndex = Math.min(dayIndex, this.data.days.length - 1);
       this.setData({
         pickerValue: [yearIndex, monthIndex, newDayIndex],
-        selectedDate: `${selectedYear}-${this.formatNum(selectedMonth)}-${this.formatNum(this.data.days[newDayIndex])}`
+        selectedDates: [...this.data.selectedDates,`${selectedYear}-${this.formatNum(selectedMonth)}-${this.formatNum(this.data.days[newDayIndex])}`],
+        date:`${selectedYear}-${this.formatNum(selectedMonth)}-${this.formatNum(this.data.days[newDayIndex])}`
       });
+      console.log(this.data.pickerValue,'date')
     },
     // 输入时实时更新
     onTitleInput(e) {
@@ -165,20 +172,23 @@ VueLikePage([], {
       console.log(123, this.data.title)
     },
     saveTitle(e) {
+      const selectedItem = e.currentTarget.dataset.item
       const currentTitle = this.data.title.trim()
-
+      console.log(selectedItem)
+      const handle = e.currentTarget.dataset.click
       // 防空判断
-      if (!currentTitle) {
+      if (!currentTitle&&handle) {
         wx.showToast({
           title: '请输入标题',
           icon: 'none'
         })
         return
+      }else if(!currentTitle){
+        return
       }
       // 追加
       this.setData({
         titleDatas: [...this.data.titleDatas, currentTitle],
-        title: '',
       })
 
       this.selectIp(e)
@@ -212,6 +222,7 @@ VueLikePage([], {
     },
     // 切换tab
     handleTabTap(e) {
+      this.confirmIp(e)
       const index = e.currentTarget.dataset.index;
       console.log(index, '11111')
       this.setData({
@@ -772,10 +783,8 @@ VueLikePage([], {
       });
     },
     selectIp(e) {
-      
       const index = e.currentTarget.dataset.index ;
       const item = this.data.ipsImgList[index];
-      console.log(index,item)
       // 这里日期和标题选择的index都没用,但是也需要传,相当于限制了添加上限为ips数组长度
       if (!item) return;
       if (this.data.selectedIp && !this.data.ipConfirmed) {
@@ -801,7 +810,6 @@ VueLikePage([], {
           query.exec((res) => {
             const container = res[0];
             const overlay = res[1];
-            console.log(container, overlay, 'index')
             if (container && overlay) {
 
               this.setData({
@@ -932,8 +940,11 @@ VueLikePage([], {
         ipConfirmed: false,
       });
     },
-    confirmIp() {
-    
+    confirmIp(e) {
+      const selectedItem2 = e.currentTarget.dataset.item
+      console.log(this.data,'12112')
+      if(this.data.tabIndex=='2')this.saveTitle(e)
+      
       if (!this.data.selectedIp) return;
       const overlayItem = {
         typeIndex: this.data.tabIndex, // 判断是贴图还是标题还是日期
@@ -941,7 +952,7 @@ VueLikePage([], {
         rgb: this.data.rgb,
         imgUrl: this.data.selectedIp.imgUrl,
         title: this.data.titleDatas[this.data.titleDatas.length - 1],
-        date: this.data.selectedDate,
+        date: this.data.date,
         scaleX: this.data.ipScaleX,
         scaleY: this.data.ipScaleY,
         rotate: this.data.ipRotate,
@@ -958,7 +969,8 @@ VueLikePage([], {
         ipScaleY: 1,
         ipRotate: 0,
         ipConfirmed: false,
-        positionInitialized: false
+        positionInitialized: false,
+        title:''
       });
     },
   },

+ 4 - 4
pages/work/index.wxml

@@ -46,11 +46,11 @@
         <!-- 标题 -->
         <view wx:if="{{tabIndex==2}}" class="ip-title-main"
           style="color:{{rgb}};transform:scale({{ipScaleX}}, {{ipScaleY}}) rotate({{ipRotate}}deg) translateZ(0); will-change: transform;"
-          catchtouchstart="dragStart" catchtouchmove="dragMove">{{titleDatas[titleDatas.length-1]}}</view>
+          catchtouchstart="dragStart" catchtouchmove="dragMove">{{title}}</view>
         <!-- 日期 -->
         <view wx:if="{{tabIndex==3}}" class="ip-title-main"
           style="color:{{rgb}};transform:scale({{ipScaleX}}, {{ipScaleY}}) rotate({{ipRotate}}deg) translateZ(0); will-change: transform;"
-          catchtouchstart="dragStart" catchtouchmove="dragMove">{{selectedDate}}</view>
+          catchtouchstart="dragStart" catchtouchmove="dragMove">{{date}}</view>
         <image class="ip-btn ip-btn__rotate" src="/assets/img/icon_rorate.png" mode="widthFix"
           catchtouchstart="rotateStart" catchtouchmove="rotateMove" />
         <image class="ip-btn ip-btn__scale" src="/assets/img/icon_scale.png" mode="widthFix"
@@ -115,7 +115,7 @@
           <color-picker bindchangeColor="pickColor" initColor="{{rgb}}" show="{{pick}}" bindclose="toPick" />
         </view>
         <view class="confirmBox">
-          <view class="cConfirm" bindtap="saveTitle" data-index="{{titleDatas.length}}">添加</view>
+          <view class="cConfirm" bindtap="saveTitle" data-click='handle' data-index="{{titleDatas.length}}">添加</view>
         </view>
       </view>
       <!-- 日期 -->
@@ -135,7 +135,7 @@
           </picker-view-column>
         </picker-view>
         <view class="confirmBox">
-          <view class="cConfirm" bindtap="selectIp" data-index="{{0}}">添加</view>
+          <view class="cConfirm" bindtap="selectIp" data-index="{{selectedDates.length}}">添加</view>
         </view>
       </view>
 

+ 5 - 3
pages/work/index.wxss

@@ -170,10 +170,12 @@
   display: flex;
   align-items: center;
   justify-content: center;
-  gap: 130rpx;
+  gap: 100rpx;
   color: rgba(51, 51, 51, 1);
 }
-
+.tabList .tab{
+  padding: 10px 10px 5px 10px;
+}
 .tabList .tab_active{
   position: relative;
   font-weight: bold;
@@ -362,7 +364,7 @@
   width: 100%;
   min-width: 140rpx;
   height: fit-content;
-  line-height: 55rpx;
+  line-height: 60rpx;
   min-height: 60rpx;
   word-break: break-all;
 }