Commit 2ffee13a authored by liubinyu's avatar liubinyu

接口

parent a7caed47
<script>
import store from '@/store'
export default {
onLaunch: function() {
console.log('App Launch')
uni.hideTabBar();
uni.getSystemInfo({
success(res) {
store.commit('xStore', { name: 'x_sys', value: res })
}
})
uni.getLocation({
success(res) {
store.commit('xStore', { name: 'x_location', value: res })
}
})
},
onShow: function() {
console.log('App Show')
......@@ -35,23 +46,8 @@
background-image: url(@/static/bg2.png);
}
@font-face {
font-family: 'FengYaShiSong';
src: url(@/static/font/FengYaShiSong-2.otf);
}
@font-face {
font-family: 'MeiGuiZhuangYuanTi';
src: url(@/static/font/AaMeiGuiZhuangYuanTi-2.ttf);
}
@font-face {
font-family: 'NotoSerif';
src: url(@/static/font/NotoSerif.ttf);
}
@font-face {
font-family: 'LiuShengChangPianJi';
src: url(@/static/font/LiuShengChangPianJi-2.ttf);
}
</style>
\ No newline at end of file
......@@ -2,12 +2,27 @@ import http from './interceptor.js'
// 游客选择星座字体查看今日所属星座运势
export function findConstellation(data) {
return http.request({ url: '/system/chatCompletionsExample/findConstellation', method: 'get', data })
return http.request({ url: '/system/chatCompletionsExample/findConstellation', method: 'GET', data })
}
// 专属运程(免费)
export function exclusiveItineraryFree(data) {
return http.request({ url: '/system/chatCompletionsExample/exclusiveItineraryFree', method: 'get', data })
return http.request({ url: '/system/chatCompletionsExample/exclusiveItineraryFree', method: 'GET', data })
}
// 解析用户输入的生日返回根据生日的星座信息(更详细)
export function analyzingBirthdays(data) {
return http.request({ url: '/system/chatCompletionsExample/analyzingBirthdays', method: 'GET', data })
}
// 获取用户信息
export function getUserName(data) {
return http.request({ url: `/system/user/getUserName${tr(data)}`, method: 'GET' })
}
// 自动注册用户
export function autoRegister(data) {
return http.request({ url: `/system/user/autoRegister`, method: 'POST', data })
}
/**
......
......@@ -10,12 +10,12 @@ http.interceptor.request = (config) => {
const token = uni.getStorageSync('token');
config.header.Authorization = token;
}
// console.log('请求:', config);
console.log('请求:', config);
return config;
}
http.interceptor.response = (res) => {
// console.log('响应:', res);
console.log('响应:', res);
if (res.code === 200) return res
else {
uni.showToast({
......
......@@ -3,13 +3,19 @@ import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
import store from '@/store';
Vue.prototype.$store = store
import i18n from './i18n'
Vue.config.productionTip = false
import $g from '@/utils/const'
Vue.prototype.$g = $g
import * as $api from '@/api'
Vue.prototype.$api = $api
App.mpType = 'app'
let vuexStore = require('@/store/mixin.js');
Vue.mixin(vuexStore);
......
......@@ -67,16 +67,39 @@
if (!res?.data) return
this.addMsg(res.data)
},
// 解析生日消息
async getAnalyz(message) {
const res = await this.$api.analyzingBirthdays({
language: this.$g.languageMap[this.$i18n.locale],
message,
userName: this.x_sys.deviceId,
})
// 如果解析成功,则重新获取生日信息
if (res?.data) {
const res = await this.$api.getUserName({ userName: this.x_sys.deviceId })
if (res?.data) {
this.vuex('x_user', res.data)
const xz = this.$g.ConstellationList.find(i => i.constellation === res.data.constellation)
xz && this.vuex('x_xz', xz)
}
}
const msg = res?.data?.[0]?.message?.content || '解析失败,请输入正确的提问格式'
this.addMsg(msg)
},
// 是否显示头像,每个用户连续的记录,只显示第一个的头像
showAvatar(item, index) {
if (index === 0) return true
else return !!item.user !== !!this.recordList[index - 1].user
},
confirm() {
async confirm() {
const txt = this.inputText.trim()
if (!txt) return uni.showToast({ title: '不能发送空白消息', icon: 'none' })
this.addMsg(txt, true)
this.inputText = ''
this.addMsg(txt, true)
// 延迟是为了先显示上一条消息
setTimeout(() => {
this.getAnalyz(txt)
}, 100)
},
// 新增记录
addMsg(content, user) {
......
......@@ -3,6 +3,7 @@
<view class="card" :class="{ back: isBack }"
:style="{ transitionDuration: `${duration}s`, transform: `scaleX(${scale})` }" @click="start">
<template v-if="!isBack && info">
<view class="zsyc">{{ $t('Exclusive Horoscope') }}</view>
<view class="title">{{ info.constellation }}</view>
<view class="date">{{ info.date }}</view>
<view class="star-list">
......@@ -30,7 +31,7 @@
<view v-if="isZS" class="btn" hover-class="btn-hover" @click="start">
{{ $t('Start') }}{{ $t('Exclusive Horoscope') }}
</view>
<view v-else class="btn" hover-class="btn-hover" @click="start">
<view v-else class="btn" hover-class="btn-hover" @click="goChat">
{{ $t('Exclusive Horoscope') }}{{ $t('(') }}{{ $t('Free') }}{{ $t(')') }}
</view>
</view>
......@@ -51,9 +52,21 @@
info: undefined, // 星座信息
};
},
onLoad() {
// 如果没选择星座,则跳转星座选择页面
if (!this.x_xz) {
watch: {
// 用户信息更新后翻面
x_user(val) {
this.isBack = true
this.info = undefined
this.isZS = val?.birthday
}
},
async onLoad() {
const res = await this.$api.getUserName({ userName: this.x_sys.deviceId })
if (res?.data) {
this.vuex('x_user', res.data)
const xz = this.$g.ConstellationList.find(i => i.constellation === res.data.constellation)
xz && this.vuex('x_xz', xz)
} else {
uni.reLaunch({
url: '/pages/index/index'
})
......@@ -78,6 +91,10 @@
})
this.info = res?.data
},
// 跳转问答页面
goChat() {
uni.switchTab({ url: '/pages/chat/chat' });
},
},
}
</script>
......@@ -92,9 +109,22 @@
background-image: url(@/static/card-front.png);
background-size: 100% 100%;
margin: 0 auto;
padding: 160rpx 60rpx 0;
padding: 150rpx 60rpx 0;
transition-property: transform;
.zsyc {
width: 180rpx;
height: 40rpx;
margin: 0 auto;
background-color: #F6CF39;
border-radius: 50rpx;
font-size: 26rpx;
color: #FCFCFC;
line-height: 40rpx;
text-align: center;
margin-bottom: 30rpx;
}
.title {
font-size: 68rpx;
text-align: center;
......
......@@ -30,11 +30,18 @@
changeXZ(xz) {
this.xz = xz
},
go() {
this.vuex('x_xz', this.xz)
uni.reLaunch({
url: '/pages/home/home'
async go() {
const res = await this.$api.autoRegister({
constellation: this.xz.constellation,
userName: this.x_sys.deviceId,
latitude: this.x_location.latitude,
longitude: this.x_location.longitude,
})
if (res?.data) {
uni.reLaunch({
url: '/pages/home/home'
})
}
},
}
}
......@@ -113,7 +120,7 @@
filter: brightness(1.1);
}
}
.page.En {
padding-top: 130rpx;
}
......
......@@ -7,10 +7,10 @@
<view class="txt">{{ $t(lang) }}</view>
</picker>
</view>
<view class="item">
<!-- <view class="item">
<view class="txt">{{ $t('Constellation Selection') }}</view>
<image class="icon" src="@/static/icon-right.svg" @click="go('/pages/index/index')"></image>
</view>
</view> -->
</view>
<tabbar />
</view>
......
......@@ -9,7 +9,7 @@ try {
console.log('本地储存:', lifeData)
} catch (e) {}
let saveStateKeys = ['x_xz'];
let saveStateKeys = ['x_xz', 'x_sys', 'x_location'];
const saveLifeData = function(key, value) {
if (saveStateKeys.indexOf(key) != -1) {
......@@ -23,6 +23,9 @@ const saveLifeData = function(key, value) {
const store = new Vuex.Store({
state: {
x_xz: lifeData.x_xz, // 用户选择的星座
x_sys: lifeData.x_sys, // 设备信息
x_location: lifeData.x_location, // 位置信息
x_user: null, // 用户信息
},
mutations: {
xStore(state, payload) {
......
// 全局常量
export default {
// baseUrl: '/api', // 正式环境
// baseUrl: 'http://47.243.113.209:8081', // 正式环境
baseUrl: 'http://192.168.200.12:8081', // 鸿波
baseUrl: 'http://47.243.113.209:8081', // 正式环境
// baseUrl: 'http://192.168.200.12:8081', // 鸿波
// 星座列表
ConstellationList: [
{ key: 'Aries', date: ['3.21', '4.19'], zodiacSignId: '1', angle: 330, constellation: '白羊' },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment