• 交友盲盒完整版——详细源码分享


    现在目前比较火热的一款app交友盲盒是通过uniapp+springboot技术来制作的,原理其实很简单,大家一看便知。

    大家自行下载到手机里面去使用即可,不支持ios手机

    演示地址:https://share.weiyun.com/l3ovztce

    下面就是给大家分享源码了,实现原理就是前端像后端发请求拿到数据渲染页面就这么简单

    首页页面: 

    1. <template>
    2. <view class="content">
    3. <view class="top">
    4. <image src="../../static/bg.png" mode="widthFix">image>
    5. view>
    6. <view class="subject">
    7. <view class="left">
    8. <view class="imgman">
    9. <image src="../../static/man.png" mode="">image>
    10. view>
    11. <view class="chair">
    12. view>
    13. <view class="man">
    14. 男生盒子
    15. view>
    16. <view class="enter" @click="enterman">
    17. 放入男生纸条
    18. view>
    19. <view class="out" @click="outman">
    20. 取出男生纸条
    21. view>
    22. view>
    23. <view class="right">
    24. <view class="imgwuman">
    25. <image src="../../static/wuman.png" mode="">image>
    26. view>
    27. <view class="chair">
    28. view>
    29. <view class="man">
    30. 女生盒子
    31. view>
    32. <view class="enter" @click="wumen">
    33. 放入女生纸条
    34. view>
    35. <view class="out" @click="outmen">
    36. 取出女生纸条
    37. view>
    38. view>
    39. view>
    40. <view class="sub">
    41. 我的纸条
    42. view>
    43. view>
    44. template>
    45. <script>
    46. export default {
    47. data() {
    48. return {
    49. title: 'Hello'
    50. }
    51. },
    52. onLoad() {
    53. },
    54. methods: {
    55. wumen() {
    56. uni.navigateTo({
    57. url: "/pages/index/from/from"
    58. })
    59. },
    60. outmen() {
    61. uni.navigateTo({
    62. url: "/pages/index/from/from1"
    63. })
    64. },
    65. enterman() {
    66. uni.navigateTo({
    67. url: "/pages/index/from/from2"
    68. })
    69. },
    70. outman() {
    71. uni.navigateTo({
    72. url: "/pages/index/from/from3"
    73. })
    74. }
    75. }
    76. }
    77. script>
    78. <style scoped lang="scss">
    79. .imgwuman {
    80. image {
    81. width: 800rpx;
    82. height: 800rpx;
    83. }
    84. position: absolute;
    85. top: -78%;
    86. left: -68%;
    87. }
    88. .imgman {
    89. image {
    90. width: 800rpx;
    91. height: 800rpx;
    92. }
    93. position: absolute;
    94. top: -78%;
    95. left: -65%;
    96. }
    97. .top {
    98. width: 100%;
    99. height: 300rpx;
    100. /* background-color: pink; */
    101. border-radius: 50rpx;
    102. box-sizing: border-box;
    103. }
    104. .top image {
    105. box-sizing: border-box;
    106. width: 100%;
    107. height: 100%;
    108. }
    109. .subject {
    110. height: 600rpx;
    111. margin-top: 10%;
    112. // background-color: aliceblue;
    113. display: flex;
    114. justify-content: center;
    115. align-items: center;
    116. }
    117. .subject .left {
    118. position: relative;
    119. width: 45%;
    120. height: 550rpx;
    121. background-color: #119DFC;
    122. margin-right: 30rpx;
    123. }
    124. .subject .left {
    125. border-radius: 20rpx;
    126. .chair {
    127. width: 200rpx;
    128. height: 30rpx;
    129. border-radius: 50rpx;
    130. background-color: #fff;
    131. margin: 50rpx auto;
    132. }
    133. .man {
    134. font-size: 50rpx;
    135. font-family: "宋体";
    136. text-align: center;
    137. color: #fff;
    138. }
    139. }
    140. .subject .right {
    141. position: relative;
    142. border-radius: 20rpx;
    143. width: 45%;
    144. height: 550rpx;
    145. background-color: #FF538F;
    146. }
    147. .subject .right {
    148. border-radius: 20rpx;
    149. .chair {
    150. width: 200rpx;
    151. height: 30rpx;
    152. border-radius: 50rpx;
    153. background-color: #fff;
    154. margin: 50rpx auto;
    155. }
    156. .man {
    157. font-size: 50rpx;
    158. font-family: "宋体";
    159. text-align: center;
    160. color: #fff;
    161. }
    162. }
    163. .enter,
    164. .out {
    165. position: relative;
    166. z-index: 9;
    167. width: 300rpx;
    168. height: 100rpx;
    169. background-color: #000;
    170. color: #fff;
    171. text-align: center;
    172. border-radius: 15rpx;
    173. margin: 0 auto;
    174. margin-top: 18%;
    175. line-height: 100rpx;
    176. }
    177. .sub {
    178. width: 90%;
    179. height: 100rpx;
    180. background-color: #FA91A8;
    181. margin: 0 auto;
    182. margin-top: 5%;
    183. border-radius: 50rpx;
    184. text-align: center;
    185. line-height: 100rpx;
    186. }
    187. style>

    男生放入卡片页面:

    1. <template>
    2. <view class="">
    3. <u-form :model="form" ref="uForm">
    4. <u-form-item label="姓名" prop="name">
    5. <u-input v-model="form.name" />
    6. u-form-item>
    7. <u-form-item label="QQ号" prop="num">
    8. <u-input v-model="form.num" />
    9. u-form-item>
    10. <u-form-item label="微信" prop="intro">
    11. <u-input v-model="form.intro" />
    12. u-form-item>
    13. <u-form-item label="手机" prop="phone">
    14. <u-input v-model="form.phone" />
    15. u-form-item>
    16. u-form>
    17. <u-button @click="submit">提交u-button>
    18. view>
    19. template>
    20. <script>
    21. export default {
    22. data() {
    23. return {
    24. form: {
    25. name: '',
    26. intro: '',
    27. num: '',
    28. phone: ''
    29. },
    30. rules: {
    31. name: [{
    32. required: true,
    33. message: '请输入姓名',
    34. // 可以单个或者同时写两个触发验证方式
    35. trigger: ['change', 'blur'],
    36. }],
    37. num: [{
    38. required: true,
    39. message: '请输入QQ号',
    40. trigger: ['change', 'blur']
    41. },
    42. {
    43. type: 'number',
    44. message: 'QQ号必须为数字',
    45. trigger: ['change']
    46. },
    47. {
    48. }
    49. ],
    50. intro: [{
    51. }]
    52. }
    53. };
    54. },
    55. methods: {
    56. submit() {
    57. let that = this;
    58. this.$refs.uForm.validate(valid => {
    59. if (valid) {
    60. console.log('验证通过');
    61. uni.request({
    62. url: "http://8.130.120.38:5531/girl/add",
    63. method: 'POST',
    64. data: {
    65. name: that.form.name,
    66. qq: that.form.num,
    67. weixi: that.form.intro,
    68. phone: that.form.phone,
    69. },
    70. success: (res => {
    71. if (res.data.data == "添加成功") {
    72. uni.showToast({
    73. title: '添加成功',
    74. mask: true
    75. });
    76. that.form.name = '';
    77. that.form.num = '';
    78. that.form.intro = '';
    79. that.form.phone = '';
    80. setTimeout(() => {
    81. uni.switchTab({
    82. url: '/pages/index/index'
    83. });
    84. }, 1500);
    85. }
    86. console.log(res);
    87. })
    88. })
    89. } else {
    90. console.log('验证失败');
    91. }
    92. });
    93. }
    94. },
    95. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
    96. onReady() {
    97. this.$refs.uForm.setRules(this.rules);
    98. }
    99. };
    100. script>

    男生取出卡片页面:

    1. <template>
    2. <view class="">
    3. <u-form :model="form" ref="uForm">
    4. <u-form-item label="姓名" prop="name">
    5. <u-input v-model="form.name" />
    6. u-form-item>
    7. <u-form-item label="QQ号" prop="num">
    8. <u-input v-model="form.num" />
    9. u-form-item>
    10. <u-form-item label="微信" prop="intro">
    11. <u-input v-model="form.intro" />
    12. u-form-item>
    13. <u-form-item label="手机" prop="phone">
    14. <u-input v-model="form.phone" />
    15. u-form-item>
    16. u-form>
    17. <u-button @click="submit">提交u-button>
    18. view>
    19. template>
    20. <script>
    21. export default {
    22. data() {
    23. return {
    24. form: {
    25. name: '',
    26. intro: '',
    27. num: '',
    28. phone: ''
    29. },
    30. rules: {
    31. name: [{
    32. required: true,
    33. message: '请输入姓名',
    34. // 可以单个或者同时写两个触发验证方式
    35. trigger: ['change', 'blur'],
    36. }],
    37. num: [{
    38. required: true,
    39. message: '请输入QQ号',
    40. trigger: ['change', 'blur']
    41. },
    42. {
    43. type: 'number',
    44. message: 'QQ号必须为数字',
    45. trigger: ['change']
    46. },
    47. ],
    48. intro: [{
    49. }]
    50. }
    51. };
    52. },
    53. methods: {
    54. submit() {
    55. let that = this;
    56. this.$refs.uForm.validate(valid => {
    57. if (valid) {
    58. console.log('验证通过');
    59. uni.request({
    60. url: "http://8.130.120.38:5531/man/add",
    61. method: 'POST',
    62. data: {
    63. name: that.form.name,
    64. qq: that.form.num,
    65. weixi: that.form.intro,
    66. phone: that.form.phone,
    67. },
    68. success: (res => {
    69. if (res.data.data == "添加成功") {
    70. uni.showToast({
    71. title: '添加成功',
    72. mask: true
    73. });
    74. that.form.name = '';
    75. that.form.num = '';
    76. that.form.intro = '';
    77. that.form.phone = '';
    78. setTimeout(() => {
    79. uni.switchTab({
    80. url: '/pages/index/index'
    81. });
    82. }, 1500);
    83. }
    84. console.log(res);
    85. })
    86. })
    87. } else {
    88. console.log('验证失败');
    89. }
    90. });
    91. }
    92. },
    93. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
    94. onReady() {
    95. this.$refs.uForm.setRules(this.rules);
    96. }
    97. };
    98. script>

    女生的取出和放入都是和男生一样的

    pages.json页面设置:

    1. {
    2. // pages.json
    3. "easycom": {
    4. "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
    5. },
    6. // "easycom": {
    7. // "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
    8. // "autoscan": true,
    9. // "custom": {
    10. // "^uni-(.*)": "@/components/uni-$1.vue", // 匹配components目录内的vue文件
    11. // "^vue-file-(.*)": "packageName/path/to/vue-file-$1.vue" // 匹配node_modules内的vue文件
    12. // }
    13. // },
    14. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
    15. {
    16. "path": "pages/index/index",
    17. "style": {
    18. "navigationBarTitleText": "交友盲盒"
    19. }
    20. }, {
    21. "path": "pages/mine/mine",
    22. "style": {
    23. "navigationBarTitleText": "个人信息",
    24. "enablePullDownRefresh": false
    25. }
    26. }, {
    27. "path": "pages/index/from/from",
    28. "style": {
    29. "navigationBarTitleText": "放入女生纸条",
    30. "enablePullDownRefresh": false
    31. }
    32. },
    33. {
    34. "path": "pages/index/from/from1",
    35. "style": {
    36. "navigationBarTitleText": "取出女生纸条",
    37. "enablePullDownRefresh": false
    38. }
    39. },
    40. {
    41. "path": "pages/index/from/from2",
    42. "style": {
    43. "navigationBarTitleText": "放入男生纸条",
    44. "enablePullDownRefresh": false
    45. }
    46. },
    47. {
    48. "path": "pages/index/from/from3",
    49. "style": {
    50. "navigationBarTitleText": "取出男生纸条",
    51. "enablePullDownRefresh": false
    52. }
    53. },
    54. {
    55. "path": "pages/getcode/getcode",
    56. "style": {
    57. "navigationBarTitleText": "取出男生信息",
    58. "enablePullDownRefresh": false
    59. }
    60. },
    61. {
    62. "path": "pages/getcode/getcodenv",
    63. "style": {
    64. "navigationBarTitleText": "取出女生信息",
    65. "enablePullDownRefresh": false
    66. }
    67. }
    68. ],
    69. "globalStyle": {
    70. "navigationBarTextStyle": "black",
    71. "navigationBarTitleText": "uni-app",
    72. "navigationBarBackgroundColor": "#F8F8F8",
    73. "backgroundColor": "#F8F8F8"
    74. },
    75. "uniIdRouter": {},
    76. "tabBar": {
    77. "selectedColor": "#F394AA",
    78. "list": [{
    79. "text": "首页",
    80. "pagePath": "pages/index/index",
    81. "iconPath": "static/sy.png",
    82. "selectedIconPath": "static/syxz.png"
    83. },
    84. {
    85. "text": "我的",
    86. "pagePath": "pages/mine/mine",
    87. "iconPath": "static/wd.png",
    88. "selectedIconPath": "static/w.png"
    89. }
    90. ]
    91. }
    92. }

    注意:代码里面使用了uview-ui框架,大家需要自己引入自己的项目哦,传送教程:https://xuqu.gitee.io/components/downloadSetting.html

  • 相关阅读:
    Obsidian之利用MaoXian获取网页信息
    Web3.0的测试题
    Jenkins系列-安装maven
    ip地址范围不是整体范围的子集
    Fecify 跨境电商系统,有哪些优势?
    5-1 Dataset和DataLoader
    精选版:用Java扩展Nginx(nginx-clojure 入门)
    swin transformer详解
    glide set gif start stop
    ESP32设备驱动-VCNL4010光传感器驱动
  • 原文地址:https://blog.csdn.net/qq_63656102/article/details/132774713