当前位置:   article > 正文

实现小程序通知功能

小程序通知

前言

这里说的是轮播图下方的通知功能。

所承受的内容一般是平台公告,当前活动。

这个功能算是通用功能,每个项目都会用到。

这个功能本身不复杂,难点在于一开始不知道有什么功能,构思上比较欠缺

需求分析

  1. 【小程序】小程序首页展示最新一条通知
  2. 【小程序】点击后查看通知列表
  3. 【小程序】点击一条通知可查看具体通知内容
  4. 【小程序】通知内容支持链接和富文本
  5. 【后台管理系统】可设置发布状态,发布后可展示在列表中
  6. 【后台管理系统】支持链接和富文本

实现

数据库

  1. /*
  2. Navicat Premium Data Transfer
  3. Source Server : 本地数据库
  4. Source Server Type : MySQL
  5. Source Server Version : 50728
  6. Source Host : localhost:3306
  7. Source Schema : yw-tmpl
  8. Target Server Type : MySQL
  9. Target Server Version : 50728
  10. File Encoding : 65001
  11. Date: 03/06/2022 20:11:24
  12. */
  13. SET NAMES utf8mb4;
  14. SET FOREIGN_KEY_CHECKS = 0;
  15. -- ----------------------------
  16. -- Table structure for com_tongzhi
  17. -- ----------------------------
  18. DROP TABLE IF EXISTS `com_tongzhi`;
  19. CREATE TABLE `com_tongzhi` (
  20. `id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主键id',
  21. `create_by` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '创建人',
  22. `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  23. `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  24. `update_by` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '修改人',
  25. `del_flag` int(11) NOT NULL DEFAULT 0 COMMENT '删除标志 默认0',
  26. `title` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '标题',
  27. `content_type` int(255) NULL DEFAULT NULL COMMENT '1.无;2.富文本;3.链接',
  28. `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '根据内容类型定',
  29. `state` int(11) NULL DEFAULT 1 COMMENT '状态:1.发布;0.未发布',
  30. PRIMARY KEY (`id`) USING BTREE
  31. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户' ROW_FORMAT = DYNAMIC;
  32. SET FOREIGN_KEY_CHECKS = 1;

后端

mapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  2. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.yanwei.tmpl.module.common.tongzhi.ComTongzhiMapper">
  4. <select id="findBySearchVo" resultType="java.util.LinkedHashMap">
  5. select
  6. bl.id as id,
  7. bl.title as title,
  8. bl.state as state,
  9. bl.content as content,
  10. bl.content_type as contentType,
  11. DATE_FORMAT(bl.create_time,'%Y-%m-%d %h:%i:%s') as createTime
  12. from com_tongzhi bl
  13. where bl.del_flag = 0
  14. <if test="searchVo.title !=null and searchVo.title !=''">
  15. and bl.title like concat('%',#{searchVo.title},'%')
  16. </if>
  17. <if test="searchVo.state!=null">
  18. and bl.state = #{searchVo.state}
  19. </if>
  20. order by bl.create_time desc
  21. </select>
  22. <select id="findHomeShow" resultType="java.util.Map">
  23. select bl.title as title
  24. from com_tongzhi bl
  25. where bl.del_flag = 0
  26. and bl.state = 1
  27. order by bl.create_time limit 1
  28. </select>
  29. </mapper>

uniapp(小程序)

  1. <template>
  2. <view class="padding-left padding-right">
  3. <yw-list ref="ywList" height="0" :pageEvent="pageEvent">
  4. <template v-slot="{ item,index }">
  5. <view class="padding-sm bg-white margin-top-sm margin-bottom-sm" @click="itemClick(item,index)">
  6. <view class="text-sm" style="height: 100rpx;">{{item.title}}</view>
  7. <view class="text-xs text-right">{{item.createTime}}</view>
  8. </view>
  9. </template>
  10. </yw-list>
  11. </view>
  12. </template>
  13. <script>
  14. import {baseTongzhiFindAllByPage} from "../../../api/api.js"
  15. export default {
  16. data() {
  17. return {
  18. searchModel:{
  19. state:1,
  20. }
  21. }
  22. },
  23. onLoad() {
  24. this.$refs.ywList.shuaxin(this.searchModel)
  25. },
  26. onShow() {
  27. uni.setNavigationBarTitle({title:`${this.$t('issuePage.notificationList')}`})
  28. },
  29. methods: {
  30. pageEvent(params){
  31. return baseTongzhiFindAllByPage(params)
  32. },
  33. itemClick(item,index){
  34. console.info(item,index)
  35. this.$common.navigateTo("/pages/commons/web-show/web-show",{
  36. type:"HTML",
  37. title:item.title,
  38. content:encodeURIComponent(item.content)
  39. })
  40. }
  41. }
  42. }
  43. </script>
  44. <style>
  45. </style>
  1. <template>
  2. <view class="bg-white padding-sm">
  3. <web-view v-if="type=='URL'" :src="content"></web-view>
  4. <!-- 插件mp-html -->
  5. <mp-html v-if="type=='HTML'" :show-img-menu="false" :content="content" />
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. type:"",
  13. content:"",
  14. }
  15. },
  16. onLoad(param) {
  17. console.info(param)
  18. this.type = param.type
  19. if(param.type == 'URL'){
  20. // encodeURIComponent(item.url)
  21. this.content = decodeURIComponent(param.content)
  22. if(this.$common.isNotBlank(param.title)){
  23. uni.setNavigationBarTitle({
  24. title:param.title
  25. })
  26. }
  27. }else if(param.type == 'HTML'){
  28. this.content = decodeURIComponent(param.content)
  29. if(this.$common.isNotBlank(param.title)){
  30. uni.setNavigationBarTitle({
  31. title:param.title
  32. })
  33. }
  34. }
  35. },
  36. methods: {
  37. }
  38. }
  39. </script>
  40. <style>
  41. </style>

代码

点击下载通知源码icon-default.png?t=M4ADhttps://download.csdn.net/download/qq_17702967/85541224

感谢

在此感谢项目提供的机会。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/963434
推荐阅读
相关标签
  

闽ICP备14008679号