Compare commits

...

2 Commits

  1. 2
      CHANGELOG.md
  2. 2
      package-lock.json
  3. 2
      package.json
  4. 7
      src/App.vue
  5. 23
      src/components/ScrollList/ScrollList.vue
  6. 1
      src/components/ScrollListItem/ScrollListItem.vue
  7. 20
      src/components/WeatherAndTime/WeatherAndTime.vue
  8. 2
      src/composables/useAutoBack.ts
  9. 6
      src/composables/useConfig.ts
  10. 17
      src/composables/useWeather.ts
  11. 5
      src/http/api/base/index.ts

2
CHANGELOG.md

@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [1.0.0-B.2](https://git.1000my.com/project_yongwangyun/YongWang_Customer/compare/v1.0.0-B.1...v1.0.0-B.2) (2023-10-27)
## 1.0.0-B.1 (2023-10-25) ## 1.0.0-B.1 (2023-10-25)

2
package-lock.json

@ -1,6 +1,6 @@
{ {
"name": "vue_cli_ts", "name": "vue_cli_ts",
"version": "1.0.0-B.1",
"version": "1.0.0-B.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "vue_cli_ts", "name": "vue_cli_ts",
"version": "1.0.0-B.1",
"version": "1.0.0-B.2",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",

7
src/App.vue

@ -1,6 +1,6 @@
<template> <template>
<WeatherAndTime />
<ScrollList ref="scrollList" />
<WeatherAndTime :mall-code="mallCode" />
<ScrollList ref="scrollList" :mall-code="mallCode" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onBeforeUnmount, ref } from 'vue' import { onMounted, onBeforeUnmount, ref } from 'vue'
@ -9,6 +9,7 @@ import WeatherAndTime from '@/components/WeatherAndTime/WeatherAndTime.vue'
import ScrollList from '@/components/ScrollList/ScrollList.vue' import ScrollList from '@/components/ScrollList/ScrollList.vue'
const scrollList = ref<InstanceType<typeof ScrollList> | null>(null) const scrollList = ref<InstanceType<typeof ScrollList> | null>(null)
const mallCode = ref<string>('')
const { checkHandleScreen } = useAutoBack(_checkHandleScreen) const { checkHandleScreen } = useAutoBack(_checkHandleScreen)
function _checkHandleScreen() { function _checkHandleScreen() {
@ -16,6 +17,8 @@ function _checkHandleScreen() {
} }
onMounted(() => { onMounted(() => {
const href = window.location.href
mallCode.value = href.split('=')[1]
window.addEventListener('touchend', checkHandleScreen) window.addEventListener('touchend', checkHandleScreen)
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {

23
src/components/ScrollList/ScrollList.vue

@ -31,7 +31,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, toRefs, onMounted } from 'vue'
import { ref, toRefs, watch } from 'vue'
import { useRootStore } from '@/store/root' import { useRootStore } from '@/store/root'
import { getCustomerList } from '@/http/api/base' import { getCustomerList } from '@/http/api/base'
import { HTTP_CODE } from '@/enums' import { HTTP_CODE } from '@/enums'
@ -39,8 +39,23 @@ import ScrollView from '@/base/ScrollView/ScrollView.vue'
import ScrollListItem from '@/components/ScrollListItem/ScrollListItem.vue' import ScrollListItem from '@/components/ScrollListItem/ScrollListItem.vue'
import Loading from '@/base/Loading/Loading.vue' import Loading from '@/base/Loading/Loading.vue'
type Props = {
mallCode: string
}
const props = withDefaults(defineProps<Props>(), {
mallCode: ''
})
watch(
() => props.mallCode,
() => {
_getCustomerList()
}
)
const store = useRootStore() const store = useRootStore()
const { config, device } = toRefs(store)
const { config } = toRefs(store)
const customerList = ref<Customer[]>([]) const customerList = ref<Customer[]>([])
const pageIndex = ref(1) const pageIndex = ref(1)
@ -54,8 +69,6 @@ function scrollEnd() {
_getCustomerList() _getCustomerList()
} }
onMounted(_getCustomerList)
function _getCustomerList() { function _getCustomerList() {
if (loading.value || loaded.value) { if (loading.value || loaded.value) {
return return
@ -64,7 +77,7 @@ function _getCustomerList() {
const params = { const params = {
pageIndex: pageIndex.value, pageIndex: pageIndex.value,
pageSize: 10, pageSize: 10,
mallCode: device.value.mallCode
mallCode: props.mallCode
} }
getCustomerList(config.value.smallUrl, params) getCustomerList(config.value.smallUrl, params)
.then(({ code, data }) => { .then(({ code, data }) => {

1
src/components/ScrollListItem/ScrollListItem.vue

@ -52,6 +52,7 @@ const store = useRootStore()
const { config } = toRefs(store) const { config } = toRefs(store)
function formatDate(date: string) { function formatDate(date: string) {
// eslint-disable-next-line newline-per-chained-call
return new Date(date).toLocaleString().replace(/\//g, '-').substring(0, 16) return new Date(date).toLocaleString().replace(/\//g, '-').substring(0, 16)
} }
</script> </script>

20
src/components/WeatherAndTime/WeatherAndTime.vue

@ -23,13 +23,31 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { watch } from 'vue'
import { formatDay } from '@/utils/utils' import { formatDay } from '@/utils/utils'
import { useWeather } from '@/composables/useWeather' import { useWeather } from '@/composables/useWeather'
import { useTime } from '@/composables/useTime' import { useTime } from '@/composables/useTime'
import { useDay } from '@/composables/useDay' import { useDay } from '@/composables/useDay'
import Icon from '@/base/Icon/Icon.vue' import Icon from '@/base/Icon/Icon.vue'
const { weather, icon } = useWeather()
type Props = {
mallCode: string
}
const props = withDefaults(defineProps<Props>(), {
mallCode: ''
})
const { weather, icon, getWeatherStatus } = useWeather()
const { currentTime } = useTime() const { currentTime } = useTime()
const { whichWeek } = useDay() const { whichWeek } = useDay()
watch(
() => props.mallCode,
(newVal: string) => {
if (newVal.length) {
getWeatherStatus(props.mallCode)
}
}
)
</script> </script>

2
src/composables/useAutoBack.ts

@ -3,7 +3,7 @@ import { ref } from 'vue'
export const useAutoBack = (callback: () => void) => { export const useAutoBack = (callback: () => void) => {
const MIN_TIME = 0 const MIN_TIME = 0
const CHECK_TIME = 1000 const CHECK_TIME = 1000
const TO_INDEX_TIME = 10
const TO_INDEX_TIME = 60
const toIndexTime = ref(TO_INDEX_TIME) //回首页的时间 const toIndexTime = ref(TO_INDEX_TIME) //回首页的时间
const toIndexInterval = ref() const toIndexInterval = ref()

6
src/composables/useConfig.ts

@ -1,13 +1,11 @@
import { getWeather, getConfig, getDevice } from '@/http/api/base'
import { getConfig } from '@/http/api/base'
import { useRootStore } from '@/store/root' import { useRootStore } from '@/store/root'
export const useConfig = async () => { export const useConfig = async () => {
const store = useRootStore() const store = useRootStore()
try { try {
const [_weather, _config, _device] = await Promise.all([getWeather(), getConfig(), getDevice()])
store.SET_WEATHER(_weather.data)
const [_config] = await Promise.all([getConfig()])
store.SET_CONFIG(_config.data) store.SET_CONFIG(_config.data)
store.SET_DEVICE(_device.data)
Promise.resolve() Promise.resolve()
} catch (error) { } catch (error) {
console.log('error: ', error) console.log('error: ', error)

17
src/composables/useWeather.ts

@ -1,12 +1,19 @@
import { ref, toRefs } from 'vue'
import { ref, toRefs, computed } from 'vue'
import { useRootStore } from '@/store/root' import { useRootStore } from '@/store/root'
import { getWeather } from '@/http/api/base'
type IconMap = { type: ExtractIcons<'sunny' | 'cloudy' | 'rain' | 'snow' | 'shade'>; status: string } type IconMap = { type: ExtractIcons<'sunny' | 'cloudy' | 'rain' | 'snow' | 'shade'>; status: string }
export const useWeather = () => { export const useWeather = () => {
const store = useRootStore() const store = useRootStore()
const { weather } = toRefs(store)
const icon = ref({} as IconMap)
const { config } = toRefs(store)
const weather = ref({} as Weather)
function getWeatherStatus(mallCode: string) {
getWeather(config.value.smallUrl, mallCode).then(({ data }) => {
weather.value = data ?? {}
})
}
const status: IconMap[] = [ const status: IconMap[] = [
{ type: 'sunny', status: '晴' }, { type: 'sunny', status: '晴' },
@ -15,7 +22,7 @@ export const useWeather = () => {
{ type: 'snow', status: '雪' }, { type: 'snow', status: '雪' },
{ type: 'shade', status: '阴' } { type: 'shade', status: '阴' }
] ]
icon.value = status.find(item => weather.value.status?.includes(item.status)) ?? status[0]
const icon = computed(() => status.find(item => weather.value.status?.includes(item.status)) ?? status[0])
return { weather, icon }
return { weather, icon, getWeatherStatus }
} }

5
src/http/api/base/index.ts

@ -4,11 +4,8 @@ import { PREFIX } from '@/enums'
//获取配置项 //获取配置项
export const getConfig = () => request<Config>({ url: `${PREFIX.STATIC_URL}/JSON/getConfig.json` }) export const getConfig = () => request<Config>({ url: `${PREFIX.STATIC_URL}/JSON/getConfig.json` })
//获取设备
export const getDevice = () => request<Device>({ url: `${PREFIX.STATIC_URL}/JSON/GetDevCoordinateByIP.json` })
//获取天气 //获取天气
export const getWeather = () => request<Weather>({ url: `${PREFIX.STATIC_URL}/JSON/GetWeathers.json` })
export const getWeather = (url: string, mallCode: string) => request<Weather>({ url: `${url}/Api/Cdn/GetWeathers?mallCode=${mallCode}` })
//获取心声列表 //获取心声列表
export const getCustomerList = (url: string, params: { pageIndex: number; pageSize: number; mallCode: string }) => { export const getCustomerList = (url: string, params: { pageIndex: number; pageSize: number; mallCode: string }) => {

Loading…
Cancel
Save