1、前言
之前做了个恋爱话术微信小法式,满足了平常聊天的需要,实现高情商的恋爱聊天。比来也完成了话术库的优化更新,新增30万条话术数据,同时利用了分词技术,婚配更完善。
但比来忽然发现,天天早上给女朋友发一段优美情话可以让她高兴一成天,但无法自己的说话水平确切有限,不能随手拈来,实在让人有点不爽。
不外法子总比困难多,作为高情商的法式猿,来历于平常生活的需求常常是我们最大的动力,必须盘他,所以想着在之前的恋爱话术小法式上在加一个逐日情话保举的功用。
希望这个法式对其他单身大概恋爱中的兄弟们有所帮助,也希望兄弟们关注加三连支持一波哈~~~ 2、保举接口简介
==辣鸡办事器,兄弟们轻点调哈==
浪漫保举情话开放接口
接口地址:https://yin-feng.top/open/getRecommendLove
请求方式:POST
请求数据范例:application/json
响应数据范例:*/*
请求参数:响应参数:
响应示例:
- [
- {
- "content": "",
- "id": 0,
- "score": 0,
- "title": ""
- }
- ]
复制代码 3、前端页面开辟
老样子,我们还是利用uniapp框架来开辟,uniapp的先容就不多说了哈。 3.1 设置pages.json文件
我们此次筹算配两个菜单,包括浪漫情话保举和话术搜索。首要在pages.json里面就行设置。
==pages.json== 文件用来对 uni-app 停止全局设置,决议页面文件的途径、窗口款式、原生的导航栏、底部的原生tabbar 等。它类似微信小法式中app.json的页面治理部分。
在 ==pages.json== 中供给 tabBar 设置,不但仅是为了方便快速开辟导航,更重要的是在App和小法式端提升性能。在这两个平台,底层原生引擎在启动时无需期待js引擎初始化,即可间接读取 pages.json 中设置的 tabBar 信息,衬着原生tab。 官方文档参考tabBar
出格留意
- 当设备 position 为 top 时,将不会显现 icon
- tabBar 中的 list 是一个数组,只能设置最少2个、最多5个 tab,tab 按数组的顺序排序。
- tabbar 切换第一次加载时能够衬着不实时,可以在每个tabbar页面的onLoad生命周期里先弹出一个期待雪花(hello uni-app利用了此方式)
- tabbar 的页面展现过一次后就保存在内存中,再次切换 tabbar 页面,只会触发每个页面的onShow,不会再触发onLoad。
- 顶部的 tabbar 今朝仅微信小法式上支持。需要用到顶部选项卡的话,倡议不利用 tabbar 的顶部设备,而是自己做顶部选项卡。
新增浪漫情话页面设置- {
- "path": "pages/recommend/recommend",
- "style": {
- "navigationBarTitleText": "浪漫情话",
- "backgroundColor": "#eeeeee",
- "enablePullDownRefresh": false
- }
- }
复制代码 增加两个tab标签- "tabBar": {
- "color": "#7A7E83",
- "selectedColor": "#0055ff",
- "borderStyle": "black",
- "backgroundColor": "#ffffe1",
- "height":"60px",
- "fontSize":"18px",
- "list": [
- {
- "pagePath": "pages/recommend/recommend",
- "iconPath": "static/imgs/love1.png",
- "selectedIconPath": "static/imgs/love2.png",
- "text": "浪漫情话"
- },
- {
- "pagePath": "pages/index/index",
- "iconPath": "static/imgs/爱心1.png",
- "selectedIconPath": "static/imgs/爱心2.png",
- "text": "话术搜索"
- }
- ]
- }
复制代码 完整的page.json文件- {
- "pages": [ //pages数组中第一项暗示利用启动页,参考:https://uniapp.dcloud.io/collocation/pages
- {
- "path": "pages/recommend/recommend",
- "style": {
- "navigationBarTitleText": "浪漫情话",
- "backgroundColor": "#eeeeee",
- "enablePullDownRefresh": false
- }
- },
- {
- "path": "pages/index/index",
- "style": {
- "navigationBarTitleText": "恋爱话术",
- "backgroundColor": "#eeeeee",
- "enablePullDownRefresh": false
- }
- }, {
- "path": "component/WebView/WebView",
- "style": {
- "navigationBarTitleText": "",
- "enablePullDownRefresh": false
- }
- }
- ],
- "tabBar": {
- "color": "#7A7E83",
- "selectedColor": "#0055ff",
- "borderStyle": "black",
- "backgroundColor": "#ffffe1",
- "height":"60px",
- "fontSize":"18px",
- "list": [
- {
- "pagePath": "pages/recommend/recommend",
- "iconPath": "static/imgs/love1.png",
- "selectedIconPath": "static/imgs/love2.png",
- "text": "浪漫情话"
- },
- {
- "pagePath": "pages/index/index",
- "iconPath": "static/imgs/爱心1.png",
- "selectedIconPath": "static/imgs/爱心2.png",
- "text": "话术搜索"
- }
- ]
- },
- "globalStyle": {
- "navigationBarTextStyle": "black",
- "navigationBarTitleText": "恋爱话术",
- "navigationBarBackgroundColor": "#ffffe1",
- "backgroundColor": "#f5ffff"
- }
- }
复制代码
在这里插入图片描写
3.2 封装api接口
首要在==http.api.js==里面设置,这个文件之前也包括了我们的话术搜索接口- import service from './http.interceptor.js'
- const api = {
- // 话术搜索
- getLoveChat: params => service.post('/open/getLoveChat', params),
- getBanner: () => service.post('/open/getBanner'),
- // 浪漫情话保举
- getRecommendLove: () => service.post('/open/getRecommendLove'),
- loveScore: params => service.post('/open/loveScore', params),
- }
- export default api
复制代码 3.3 编写浪漫情话页面
我们还是利用vue3加uniapp的语法停止页面开辟,同时为了使页面更优美,封装一个瀑布流组件停止衬着数据。下图就是我们要实现的大致结果
在这里插入图片描写
3.3.1 封装瀑布流组件
- <template>
- <view class=&#34;u-waterfall&#34;>
- <view id=&#34;u-left-column&#34; class=&#34;u-column&#34;>
- <slot name=&#34;left&#34; :leftList=&#34;leftList&#34;></slot>
- </view>
- <view id=&#34;u-right-column&#34; class=&#34;u-column&#34;>
- <slot name=&#34;right&#34; :rightList=&#34;rightList&#34;></slot>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: &#34;waterfall&#34;,
- props: {
- value: {
- // 瀑布流数据
- type: Array,
- required: true,
- default: function() {
- return [];
- }
- }
- },
- data() {
- return {
- leftList: [],
- rightList: [],
- tempList: []
- }
- },
- watch: {
- copyFlowList(nVal, oVal) {
- this.tempList = this.cloneData(this.copyFlowList);
- this.leftList = []
- this.rightList = []
- this.splitData();
- }
- },
- mounted() {
- this.tempList = this.cloneData(this.copyFlowList);
- this.splitData();
- },
- computed: {
- // 破坏flowList变量的援用,否则watch的成果新旧值是一样的
- copyFlowList() {
- return this.cloneData(this.value);
- }
- },
- methods: {
- async splitData() {
- if (!this.tempList.length) return;
- let leftRect = await this.$uGetRect(&#39;#u-left-column&#39;);
- let rightRect = await this.$uGetRect(&#39;#u-right-column&#39;);
- // 假如左侧小于或即是右侧,就增加到左侧,否则增加到右侧
- let item = this.tempList[0];
- // 处理屡次快速上拉后,能够数据会乱的题目,由于经过上面的两个await节点查询阻塞一按时候,加上前面的按时器干扰
- // 数组能够酿成[],致使此item值能够为undefined
- if (!item) return;
- if (leftRect.height < rightRect.height) {
- this.leftList.push(item);
- } else if (leftRect.height > rightRect.height) {
- this.rightList.push(item);
- } else {
- // 这里是为了保证第一和第二张增加时,左右都能有内容
- // 由于增加第一张,现实行列的高度能够还是0,这时需要按照行列元素长度判定下一个该放哪边
- if (this.leftList.length <= this.rightList.length) {
- this.leftList.push(item);
- } else {
- this.rightList.push(item);
- }
- }
- // 移除姑且列表的第一项
- this.tempList.splice(0, 1);
- // 假如姑且数组还稀有据,继续循环
- if (this.tempList.length) {
- this.splitData();
- } else {
- // 在这里模拟触发 我们界说的全局事务 实现数据通讯的目标
- let height = (leftRect.height > rightRect.height ? leftRect.height : rightRect.height) + 120
- uni.$emit(&#39;swiperHeightChange&#39;, height + &#39;px&#39;)
- }
- },
- // 复制而不是援用工具和数组
- cloneData(data) {
- return JSON.parse(JSON.stringify(data));
- },
- }
- }
- </script>
- <style lang=&#34;scss&#34; scoped>
- @mixin vue-flex($direction: row) {
- /* #ifndef APP-NVUE */
- display: flex;
- flex-direction: $direction;
- /* #endif */
- }
- .u-waterfall {
- @include vue-flex;
- flex-direction: row;
- align-items: flex-start;
- }
- .u-column {
- @include vue-flex;
- flex: 1;
- flex-direction: column;
- height: auto;
- }
- .u-image {
- width: 100%;
- }
- </style>
复制代码 3.3.2 template代码编写
- <template>
- <view>
- <view class=&#34;change&#34; @click=&#34;changeContent&#34;>
- 没找到想要的?赶紧点击这里
- <text class=&#34;change-btn&#34;>换一批</text>
- <view class=&#34;card&#34;>
- 点击下方卡片可间接复制
- </view>
- </view>
- <waterfall :value=&#34;dataList&#34;>
- <template v-slot:left=&#34;left&#34;>
- <view v-for=&#34;item in left.leftList&#34; :key=&#34;item.id&#34; class=&#34;left-content&#34; @click=&#34;copy(item)&#34;>
- <view class=&#34;item&#34;>
- {{item.content}}
- </view>
- </view>
- </template>
- <template v-slot:right=&#34;right&#34;>
- <view v-for=&#34;item in right.rightList&#34; :key=&#34;item.id&#34; class=&#34;right-content&#34; @click=&#34;copy(item)&#34;>
- <view class=&#34;item&#34;>
- {{item.content}}
- </view>
- </view>
- </template>
- </waterfall>
- </view>
- </template>
复制代码 3.3.3 js焦点方式编写
关键代码也不多,主如果一些请求数据的方式和响应式变量的界说。 - <script>
- import {
- toRefs,
- reactive,
- onMounted
- } from &#39;vue&#39;
- import waterfall from &#39;../../component/waterfall/index.vue&#39;
- import api from &#39;../../axios/http.api.js&#39;
- export default {
- name: &#39;content&#39;,
- components: {
- waterfall
- },
- setup() {
- const state = reactive({
- dataList: [],
- loading: false,
- })
- const methods = reactive({
- getRecommendLove: async () => {
- state.loading = true
- let res = await api.getRecommendLove()
- state.loading = false
- if (res.code) {
- uni.showToast({
- title: res.msg,
- icon: &#39;none&#39;,
- position: &#39;top&#39;
- })
- }
- state.dataList = res.data
- },
- copy(item) {
- // 复制话术到剪切板
- uni.setClipboardData({
- data: item.content
- })
- methods.score(item.id)
- },
- // 换一批
- changeContent() {
- methods.getRecommendLove()
- },
- // 打分
- async score(id) {
- let res = await api.loveScore({
- id
- })
- if (res.code) {
- uni.showToast({
- title: res.msg,
- icon: &#39;none&#39;,
- position: &#39;top&#39;
- })
- }
- }
- })
- onMounted(() => {
- methods.getRecommendLove()
- // 分享菜单
- wx.showShareMenu({
- withShareTicket: true,
- menus: [&#39;shareAppMessage&#39;, &#39;shareTimeline&#39;]
- })
- })
- return {
- ...toRefs(state),
- ...toRefs(methods)
- }
- }
- }
- </script>
复制代码 3.3.4 css款式代码编写
我们究竟不是专业的前端,所以款式就随意对付一下就行,兄弟们不要介意哈 - <style lang=&#34;less&#34; scoped>
- .change {
- width: 100%;
- height: 120px;
- border-bottom: 2px #aaaaff solid;
- border-radius: 0 0 50px 50px;
- background-size: 100% 100%;
- opacity: 0.8;
- padding-top: 45px;
- text-align: center;
- font-size: 20px;
- color: #000000;
- background-image: url(../../static/imgs/img4.png);
- .change-btn {
- display: inline-block;
- padding: 2px;
- color: red;
- }
- .card {
- padding-top: 12px;
- font-size: 13px;
- }
- }
- .left-content {
- margin: 15px 5px 15px 10px;
- padding: 8px;
- border-radius: 6px;
- background: #aaffff linear-gradient(44deg, #aaffff 0%, #F4F8FF 100%);
- font-size: 16px;
- letter-spacing: 5px;
- .item {
- margin-bottom: 10px;
- }
- }
- .right-content {
- margin: 15px 10px 15px 5px;
- padding: 8px;
- border-radius: 6px;
- background: #aaffff linear-gradient(44deg, #aaffff 0%, #F4F8FF 100%);
- font-size: 16px;
- letter-spacing: 5px;
- .item {
- margin-bottom: 10px;
- }
- }
- </style>
复制代码
在这里插入图片描写
4、公布微信小法式
在这里插入图片描写
兄弟们可以扫描下面的太阳码停止体验哈
在这里插入图片描写
5、总结
源码地址在这哈,会连结一向开源,希望兄弟们多多支持,==下了源码的老铁麻烦点个star哈==- // 下了源码的老铁麻烦点个star哈
- https://gitee.com/yinfeng-code/love-chat-wx.git
复制代码肝文不易,希望对其他单身大概恋爱中的兄弟们有所帮助,也希望兄弟们==关注加三连==支持一波哈 |