耀极客论坛

 找回密码
 立即注册
查看: 895|回复: 0

JS实现课程表小程序(仿超级课程表)加入自定义背景功能

[复制链接]

1630

主题

1517

回帖

22万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
229090
发表于 2022-5-7 01:21:42 | 显示全部楼层 |阅读模式
  这篇文章主要介绍了JS实现课程表小程序(仿超级课程表)加入自定义背景功能,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
总览:
  借鉴了市面上存在的几个课程表软件,因为功能太繁杂,于是自己尝试做了个课程表小程序并开源,目前已经支持添加删除课程表功能,还加入了日课表
总体来说感觉是一个相当简洁的课程表,后端基于fastadmin开发
gif演示:

  在底部会放上gitee的开源地址
  最近总感觉目前的界面过于简洁了,不满足我这个体面人的需求,故加入自定义课程表背景的的功能。
新增页面:

  效果:

  需要在mine.js里面加入一个入口:
  1. {
  2.                 name: "设置课表背景",
  3.                 icon: "/images/scheduleIcon.png",
  4.                 url: "/pages/schedule/schedule?",
  5.             },
复制代码
  新增页面schedule
  wxml代码
  1. ‹view>
  2.     ‹view class="cu-bar ev-fr-start" bindtap="BackPage">
  3.         ‹text class="cuIcon-back padding-lr-sm">‹/text>
  4.         ‹view class="action">{{couples? "给Ta设置背景":"设置课表背景"}}‹/view>
  5.     ‹/view>
  6. ‹/view>
  7. ‹view wx:if="{{couples}}" class="ev-mainBody">
  8.     ‹view class="ev-fc-center">
  9.         ‹view wx:if="{{!CouplesBG}}" data-type='Couples' bind:tap="modifyImage" class="addBG ev-fc-center">
  10.             ‹text class="cuIcon-roundadd">‹/text>
  11.             ‹text class="padding-xs">上传背景‹/text>
  12.         ‹/view>
  13.         ‹view wx:if="{{CouplesBG}}" class="BGBox ev-fc-center">
  14.             ‹view class="BGImg" data-type='Couples' bind:tap="modifyImage">
  15.                 ‹image mode="aspectFill" src="{{CouplesBG}}" />
  16.             ‹/view>
  17.             ‹view class="round BGState">情侣课表背景‹/view>
  18.         ‹/view>
  19.     ‹/view>
  20.     ‹view class="padding-top">
  21.         ‹view class="title">背景开始展示时间‹/view>
  22.         ‹dateTimePicker type="minute" bind:change="TimePicker">
  23.             ‹view class="sendTimeBox ev-fr">
  24.                 ‹input type="text" class="sendTime padding-lr" disabled="{{true}}" value="{{sendTime}}" />
  25.                 ‹text class="cuIcon-triangledownfill padding-lr-sm">‹/text>
  26.             ‹/view>
  27.         ‹/dateTimePicker>
  28.     ‹/view>
  29.     ‹view class="padding-top">
  30.         ‹view class="title">设置背景展示时长‹/view>
  31.         ‹button wx:for="{{displayTimeList}}" wx:key="index" class="cu-btn round margin-tb {{item.checked ? 'bg-blue':''}} margin-right" data-id="{{index}}" bind:tap="showTime">
  32.             {{item.label}}
  33.         ‹/button>
  34.     ‹/view>
  35.     ‹button bind:tap="saveCouplesBG" disabled="{{!CouplesBG}}" class="cu-btn block bg-blue margin-tb-sm lg saveButton" type="">
  36.         保存
  37.     ‹/button>
  38. ‹/view>
  39. ‹view wx:else class="ev-mainBody">
  40.     ‹view>
  41.         ‹image class="message" mode="scaleToFill" src="/images/scheduleIcon.png" />
  42.     ‹/view>
  43.     ‹view>
  44.         ‹text class="title">设置课表背景‹/text>
  45.         ‹view class="padding-top-sm tips">用户可上传喜欢的图片作为课表的背景展示(点击图片替换)‹/view>
  46.     ‹/view>
  47.     ‹view class="ev-fr BGListBox">
  48.         ‹view wx:if="{{dailySchedule}}" class="BGBox ev-fc-center">
  49.             ‹view class="BGImg" data-type='daily' bind:tap="modifyImage">
  50.                 ‹image mode="aspectFill" src="{{dailySchedule}}" />
  51.             ‹/view>
  52.             ‹view class="round BGState">日课表背景‹/view>
  53.         ‹/view>
  54.         ‹view wx:if="{{!dailySchedule}}" data-type='daily' bind:tap="modifyImage" class="addBG ev-fc-center">
  55.             ‹text class="cuIcon-roundadd">‹/text>
  56.             ‹text class="padding-xs">上传日课表背景‹/text>
  57.         ‹/view>
  58.         ‹view wx:if="{{weeklySchedule}}" class="BGBox ev-fc-center">
  59.             ‹view class="BGImg" data-type='week' bind:tap="modifyImage">
  60.                 ‹image mode="aspectFill" src="{{weeklySchedule}}" />
  61.             ‹/view>
  62.             ‹view class="round BGState">周课表背景‹/view>
  63.         ‹/view>
  64.         ‹view wx:if="{{!weeklySchedule}}" data-type='week' bind:tap="modifyImage" class="addBG ev-fc-center">
  65.             ‹text class="cuIcon-roundadd">‹/text>
  66.             ‹text class="padding-xs">上传周课表背景‹/text>
  67.         ‹/view>
  68.     ‹/view>
  69.     ‹button wx:if="{{(weeklySchedule || dailySchedule)}}" bind:tap="saveButton" class="cu-btn block bg-blue margin-tb-sm lg saveButton" type="">
  70.         恢复默认背景
  71.     ‹/button>
  72. ‹/view>
复制代码
  js代码
  1. import {
  2.     scheduleBG,
  3.     couplesBG,
  4.     couplesInfoAdd,
  5.     setbgdefault,
  6. } from "../../utils/api/user";
  7. //获取应用实例
  8. const app = getApp();
  9. const dayjs = require("../../utils/dayjs/dayjs.min");
  10. import { wxShowToast } from "../../utils/promisify";
  11. Page({
  12.     data: {
  13.         StatusBar: app.globalData.StatusBar,
  14.         CustomBar: app.globalData.CustomBar,
  15.         ImgUrl: app.globalData.ImgUrl,
  16.         displayArea: app.globalData.displayArea,
  17.         CouplesBG: null, // 情侣课表背景
  18.         dailySchedule: null, // 日课表背景
  19.         weeklySchedule: null, // 周课表背景
  20.         sendTime: "现在", // 情侣课表背景开始时间
  21.         displayTimeList: [
  22.             {
  23.                 label: "一天",
  24.                 checked: false,
  25.                 time: 1,
  26.             },
  27.             {
  28.                 label: "一周",
  29.                 checked: true,
  30.                 time: 7,
  31.             },
  32.             {
  33.                 label: "一个月",
  34.                 checked: false,
  35.                 time: 30,
  36.             },
  37.         ],
  38.         startTime: null,
  39.     },
  40.     onLoad: function (query) {
  41.         let { index_bgimage, table_bgimage } = app.globalData.userInfo;
  42.         this.setData({
  43.             couples: query.couples ? query.couples : null,
  44.             dailySchedule: index_bgimage
  45.                 ? app.globalData.ImgUrl + index_bgimage
  46.                 : null, // 日课表背景
  47.             weeklySchedule: table_bgimage
  48.                 ? app.globalData.ImgUrl + table_bgimage
  49.                 : null, // 周课表背景
  50.         });
  51.     },
  52.     /**
  53.      * 后退一页
  54.      */
  55.     BackPage() {
  56.         wx.navigateBack({
  57.             delta: 1,
  58.         });
  59.     },
  60.     /**
  61.      * 切换展示时间
  62.      */
  63.     showTime(e) {
  64.         let id = e.currentTarget.dataset.id;
  65.         console.log(e.currentTarget.dataset.id);
  66.         let displayTimeList = this.data.displayTimeList.map((v, i) => {
  67.             v.checked = id === i;
  68.             return v;
  69.         });
  70.         this.setData({
  71.             displayTimeList,
  72.         });
  73.     },
  74.     /**
  75.      * 修改背景
  76.      */
  77.     modifyImage(e) {
  78.         let type = e.currentTarget.dataset.type;
  79.         wx.chooseImage({
  80.             count: 1,
  81.             sizeType: ["compressed"],
  82.             sourceType: ["album"],
  83.             success: (res) => {
  84.                 // tempFilePath可以作为img标签的src属性显示图片
  85.                 const tempFilePaths = res.tempFilePaths;
  86.                 switch (type) {
  87.                 case "week":
  88.                     scheduleBG(tempFilePaths[0], "table").then((v) => {
  89.                         app.getSet();
  90.                         v.code && wxShowToast(v.msg);
  91.                         this.setData({
  92.                             weeklySchedule: tempFilePaths[0],
  93.                         });
  94.                     });
  95.                     break;
  96.                 case "daily":
  97.                     scheduleBG(tempFilePaths[0], "index").then((v) => {
  98.                         app.getSet();
  99.                         v.code && wxShowToast(v.msg);
  100.                         this.setData({
  101.                             dailySchedule: tempFilePaths[0],
  102.                         });
  103.                     });
  104.                     break;
  105.                 case "Couples":
  106.                     couplesBG(tempFilePaths[0]).then((v) => {
  107.                         console.log(v);
  108.                         app.getSet();
  109.                         v.code && wxShowToast(v.msg);
  110.                         this.setData({
  111.                             CouplesBG:
  112.                                     app.globalData.ImgUrl + v.data.imgurl,
  113.                         });
  114.                     });
  115.                     break;
  116.                 default:
  117.                     wxShowToast("设置失败,请重试");
  118.                     break;
  119.                 }
  120.             },
  121.         });
  122.     },
  123.     /**
  124.      * 恢复默认背景
  125.      */
  126.     saveButton() {
  127.         this.setData({
  128.             dailySchedule: null,
  129.             weeklySchedule: null,
  130.         });
  131.         setbgdefault().then((v) => {
  132.             v.code && wxShowToast(v.msg);
  133.             app.getSet();
  134.         });
  135.     },
  136.     /**
  137.      * 情侣课表开始时间
  138.      */
  139.     TimePicker(e) {
  140.         let day = dayjs(e.detail).format("MM月DD日");
  141.         let am = dayjs(e.detail).format("A") == "PM" ? "下午" : "上午";
  142.         let time = dayjs(e.detail).format("HH:mm");
  143.         let sendTime = `${day} ${am} ${time}`;
  144.         console.log(sendTime, "TimePicker");
  145.         this.setData({
  146.             sendTime,
  147.             startTime: dayjs(e.detail),
  148.         });
  149.     },
  150.     /**
  151.      * 保存情侣背景
  152.      */
  153.     saveCouplesBG() {
  154.         let { displayTimeList, startTime, CouplesBG } = this.data;
  155.         let endType = displayTimeList.filter((v) => v.checked === true)[0];
  156.         let _startTime = startTime ? dayjs(startTime) : dayjs();
  157.         let endTime = endType.time;
  158.         let tid = app.globalData.userInfo.lovers_id;
  159.         if (!tid) {
  160.             wx.showToast({
  161.                 title: "保存失败",
  162.                 icon: "none",
  163.                 duration: 2000,
  164.             });
  165.             return;
  166.         }
  167.         couplesInfoAdd({
  168.             tid,
  169.             starttime: _startTime.unix(),
  170.             endtime: endTime,
  171.             love_sort: 1,
  172.             contents: CouplesBG.replace(this.data.ImgUrl, ""),
  173.         }).then((v) => {
  174.             wxShowToast(v.msg);
  175.             if (v.code) {
  176.                 app.getSet().then(() => {
  177.                     this.BackPage();
  178.                 });
  179.             }
  180.         });
  181.     },
  182. });
复制代码
  wss代码
  1. headBox {
  2.   width: 750rpx; }
  3. page {
  4.   background-color: #fff; }
  5. .BGListBox {
  6.   flex-wrap: wrap;
  7.   justify-content: space-between; }
  8. .BGBox {
  9.   width: 321rpx;
  10.   height: 321rpx;
  11.   border-radius: 34rpx;
  12.   overflow: hidden;
  13.   margin-top: 22rpx; }
  14.   .BGBox .BGImg {
  15.     width: 321rpx;
  16.     height: 321rpx; }
  17.   .BGBox .BGState {
  18.     position: relative;
  19.     background: #000000;
  20.     opacity: 0.5;
  21.     padding: 10rpx 20rpx;
  22.     bottom: 50rpx;
  23.     color: #fff; }
  24. .addBG {
  25.   width: 321rpx;
  26.   height: 321rpx;
  27.   margin-top: 22rpx;
  28.   border: 1rpx dashed #92979d;
  29.   border-radius: 24rpx;
  30.   border-radius: 34rpx; }
  31. .message {
  32.   width: 70rpx;
  33.   height: 70rpx;
  34.   margin-top: 20rpx; }
  35. .title {
  36.   font-size: 32rpx;
  37.   font-weight: 500;
  38.   line-height: 45rpx;
  39.   color: #282b2f; }
  40. .tips {
  41.   font-size: 24rpx;
  42.   font-weight: 400;
  43.   line-height: 33rpx;
  44.   color: #92979d; }
  45. .sendTimeBox {
  46.   width: 686rpx;
  47.   height: 90rpx;
  48.   background: #ffffff;
  49.   border: 1rpx solid #dfe4ea;
  50.   border-radius: 14rpx;
  51.   margin: 24rpx 0; }
复制代码
  *** 开源地址:
gitee开源: (https://gitee.com/chengdu-gengzixin_liu-jiyuan/timetable)
  到此这篇关于JS实现课程表小程序(仿超级课程表)加入自定义背景功能的文章就介绍到这了,更多相关超级课程表内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|耀极客论坛 ( 粤ICP备2022052845号-2 )|网站地图

GMT+8, 2023-3-24 13:18 , Processed in 0.068602 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表