• 小程序随机生成文字卡片文案海报,带分享保存


    概述

    文字随机生成、更换头像、生成卡片、保存卡片、分享卡片

    详细

    文字随机生成、更换头像、生成卡片、保存卡片、分享卡片

    1624858381772.gif

    数据是在data.js中

    1624859066187095498.png

    随机文案获取:

    1624859218434010154.png

    demo直接在微信开发者工具可以运行

    index.xml 代码

    1. <view class="index">
    2. <view class="center">
    3. <!-- 卡片 -->
    4. <view class="card">
    5. <view class="additional">
    6. <picker range-key="name" mode="selector" bindchange="bindPickerChange" value="{{index}}" range="{{imgList}}">
    7. <view>
    8. <image class="card-avantar ps" src="{{avatar}}" />
    9. </view>
    10. </picker>
    11. <view class="points ps" bindtap="changeName">{{name}}</view>
    12. </view>
    13. <view class="general">
    14. <textarea bindinput="inputFn" maxlength="1000" placeholder="请输入内容" class="text" value="{{value}}" />
    15. <view class="time">{{time}}</view>
    16. </view>
    17. </view>
    18. <!-- 按钮 -->
    19. <view class="buttonWrap">
    20. <view class="btn" bindtap="copy">复制文字</view>
    21. <view class="btn" bindtap="randeNext">随机生成</view>
    22. <view class="btn" bindtap="openAD">生成卡片</view>
    23. </view>
    24. <!-- 说明 -->
    25. <view class="tips">
    26. <view class="title">使用说明</view>
    27. <view class="tip">1、点击头像可切换图片</view>
    28. <view class="tip">2、点击昵称处可自定义昵称,长度不得超过6个字符</view>
    29. </view>
    30. </view>
    31. </view>

    index.js 代码

    1. const app = getApp()
    2. const {
    3. allData
    4. } = require('../data.js');
    5. const {
    6. jin
    7. } = require('../jin.js');
    8. const jinArr = jin.split(',');
    9. let arrays = [];
    10. const a = require("../../utils/util.js");
    11. const s = ['晴', '雨', '多云', '雷雨', '阵雨', '小雨', '阴'];
    12. for (let id = 0; id < 81; id++) {
    13. arrays.push(id)
    14. }
    15. function resetArr(arr) {
    16. let newArr = [];
    17. for (var i = arr.length + 1; i > 0;) {
    18. i--
    19. var rdm = Math.floor(Math.random() * arr.length)
    20. if (!newArr.includes(arr[rdm])) {
    21. newArr.push(arr[rdm])
    22. } else {
    23. if (newArr.length == arr.length) {
    24. break;
    25. }
    26. i++
    27. }
    28. }
    29. return newArr;
    30. }
    31. Page({
    32. data: {
    33. value: "",
    34. datas: [],
    35. time: '',
    36. name: '一号',
    37. avatar: "/img/1.jpg",
    38. pickValue: 0,
    39. imgList: [{
    40. id: "/img/1.jpg",
    41. name: "熊猫-男"
    42. }, {
    43. id: "/img/2.jpg",
    44. name: "熊猫-女"
    45. }, {
    46. id: "/img/3.jpg",
    47. name: "卡通狗头"
    48. }],
    49. openWrap: false,
    50. openName: 'modal',
    51. nicheng: '',
    52. jinci: ''
    53. },
    54. onLoad: function () {
    55. const that = this;
    56. const name = wx.getStorageSync('name');
    57. const avatar = wx.getStorageSync('avatar');
    58. if (name && avatar) {
    59. this.setData({
    60. avatar,
    61. name
    62. });
    63. }
    64. this.randomNumber();
    65. this.bindRandomText();
    66. },
    67. onReady: function () {
    68. },
    69. onShow: function () {
    70. },
    71. randomDateType: function () {
    72. const e = new Date();
    73. const t = "星期" + "天一二三四五六 ".charAt(e.getDay());
    74. return a.formatDate2(e) + " " + t + " ";
    75. },
    76. randomNumber: function () {
    77. let n = 1 , m = allData.length
    78. let aNumber = parseInt((n - m) * Math.random() + m);
    79. this.setData({
    80. value: allData[aNumber].text
    81. });
    82. },
    83. randomText: function () {
    84. var e = a.randomNum(0, s.length - 1);
    85. return s[e];
    86. },
    87. bindRandomText: function (e) {
    88. this.setData({
    89. time: this.randomDateType()
    90. });
    91. },
    92. randeNext: function () {
    93. let n = 1 , m = allData.length
    94. let aNumber = parseInt((n - m) * Math.random() + m);
    95. this.setData({
    96. value: allData[aNumber].text
    97. });
    98. },
    99. copy: function () {
    100. const {
    101. value,
    102. time
    103. } = this.data;
    104. wx.setClipboardData({
    105. data: `${time} ${value}`,
    106. success(res) {
    107. wx.showToast({
    108. title: "复制成功!"
    109. });
    110. }
    111. })
    112. },
    113. openAD: function () {
    114. const {
    115. name
    116. } = this.data;
    117. if (name === '设置昵称') {
    118. return wx.showToast({
    119. title: "请设置昵称",
    120. icon: "none"
    121. });
    122. }
    123. this.createCard();
    124. },
    125. createCard: function () {
    126. const {
    127. value,
    128. name,
    129. avatar,
    130. time
    131. } = this.data;
    132. var isOk = true;
    133. if (name === '设置昵称') {
    134. return wx.showToast({
    135. title: "请设置昵称",
    136. icon: "none"
    137. });
    138. }
    139. wx.showLoading({
    140. title: "内容检测中..."
    141. });
    142. for (let i = 0; i < jinArr.length; i++) {
    143. if (value.includes(jinArr[i])) {
    144. isOk = false;
    145. console.log(jinArr[i]);
    146. this.setData({
    147. jinci: jinArr[i]
    148. });
    149. break;
    150. };
    151. }
    152. if (isOk) {
    153. app.globalData.result = {
    154. value,
    155. name,
    156. avatar,
    157. time
    158. }
    159. wx.setStorageSync('avatar', avatar);
    160. this.setData({
    161. jinci: ''
    162. }, () => {
    163. wx.navigateTo({
    164. url: '/pages/result/index'
    165. });
    166. })
    167. } else {
    168. wx.showModal({
    169. title: "检测到有违禁词",
    170. content: `当前检测到违禁词 ${this.data.jinci},请更新后再提交`
    171. })
    172. }
    173. wx.hideLoading();
    174. },
    175. inputFn: function (e) {
    176. const {
    177. value
    178. } = e.detail;
    179. this.setData({
    180. value
    181. });
    182. },
    183. changeName: function () {
    184. this.setData({
    185. openWrap: true,
    186. openName: "modal open"
    187. });
    188. },
    189. close: function () {
    190. this.setData({
    191. openName: "modal",
    192. openWrap: false
    193. });
    194. },
    195. nichengInput: function (e) {
    196. const {
    197. value
    198. } = e.detail;
    199. this.setData({
    200. nicheng: value
    201. });
    202. },
    203. cName: function () {
    204. const {
    205. nicheng
    206. } = this.data;
    207. var isOk = true;
    208. if (!nicheng.trim()) {
    209. return wx.showToast({
    210. title: '昵称不能为空!',
    211. icon: "none"
    212. });
    213. }
    214. wx.showLoading({
    215. title: "昵称检测中..."
    216. });
    217. for (let i = 0; i < jinArr.length; i++) {
    218. if (nicheng.includes(jinArr[i])) {
    219. isOk = false;
    220. console.log(jinArr[i]);
    221. this.setData({
    222. jinci: jinArr[i]
    223. });
    224. break;
    225. };
    226. }
    227. if (isOk) {
    228. wx.showToast({
    229. title: "设置成功!"
    230. });
    231. this.setData({
    232. jinci: '',
    233. openName: "modal",
    234. openWrap: false,
    235. name: nicheng
    236. });
    237. wx.setStorageSync('name', nicheng);
    238. } else {
    239. wx.showModal({
    240. title: "检测到有违禁词",
    241. content: `当前检测到违禁词 ${this.data.jinci},请更新后再提交`
    242. })
    243. }
    244. wx.hideLoading()
    245. },
    246. bindPickerChange: function (e) {
    247. const {
    248. value
    249. } = e.detail;
    250. const {
    251. imgList
    252. } = this.data;
    253. this.setData({
    254. pickValue: value,
    255. avatar: imgList[value].id
    256. });
    257. wx.setStorageSync('avatar', imgList[value].id);
    258. },
    259. onShareAppMessage: function (e) {
    260. return {
    261. title: "做舔狗呢,最重要的是开心",
    262. path: "/pages/index/index",
    263. imageUrl: '/img/1.jpg'
    264. };
    265. },
    266. })

    index.css 代码

    1. page{
    2. background: #eeeeee;
    3. }
    4. .center{
    5. padding: 30rpx;
    6. box-sizing: border-box;
    7. }
    8. .card-avantar{
    9. width: 160rpx;
    10. height: 160rpx;
    11. border-radius: 80rpx;
    12. }
    13. .card{
    14. display: flex;
    15. flex-flow: column;
    16. align-items: center;
    17. background: #ffffff;
    18. padding: 30rpx;
    19. border-radius: 20rpx;
    20. }
    21. .points{
    22. text-align: center;
    23. }
    24. .general{
    25. width: 100%;
    26. font-size: 34rpx;
    27. }
    28. .text{
    29. width: 100%;
    30. height: 340rpx;
    31. padding: 40rpx 0;
    32. }
    33. .time{
    34. text-align: right;
    35. }
    36. .buttonWrap{
    37. display: flex;
    38. }
    39. .btn{
    40. width: 33.3%;
    41. text-align: center;
    42. background-color: rgb(255, 185, 127);
    43. margin:50rpx 20rpx;
    44. color: #ffffff;
    45. font-size: 30rpx;
    46. padding: 10rpx;
    47. border-radius: 10rpx;
    48. }
    49. .tips{
    50. font-size: 32rpx;
    51. line-height: 60rpx;
    52. }

    项目结构图:

    image.png

  • 相关阅读:
    计算机竞赛 目标检测-行人车辆检测流量计数
    地震勘探原理部分问题解答
    YOLOv8-Seg改进: 全局多头自注意力MHSA,效果秒杀CBAM、SE | 分割注意力系列篇
    API网关是如何提升API接口安全管控能力的
    网络安全应急响应:网络窃听安全事件检测
    使用 Redis BitMap 实现签到与查询历史签到以及签到统计功能(SpringBoot环境)
    powershell环境变量
    @SpringBootApplication注解说明(InsCode AI 创作助手)
    springboot整合log4j2
    mysql-sql操作
  • 原文地址:https://blog.csdn.net/hanjiepo/article/details/133027588