hookehuyr

调整push,replace跳转函数,按钮颜色配置调整

......@@ -10,3 +10,14 @@ export function useGo () {
}
return go
}
export function useReplace () {
let router = useRouter()
function replace (path, query) {
router.replace({
path: path,
query: query
})
}
return replace
}
......
export default {
defaultPageSize: 10,
}
import { ref } from 'vue';
export const styleObject1 = ref({
backgroundColor: '#FFFFFF',
color: '#0B3A72',
borderColor: '#0B3A72'
})
export const styleObject2 = ref({
backgroundColor: '#F9D95C',
color: '#0B3A72',
borderColor: '#F9D95C'
})
import { defineStore } from 'pinia';
// import { testStore } from './test'; // 另一个store
import _ from 'lodash';
import { useRoute, useRouter } from 'vue-router'
const $route = useRoute();
export const mainStore = defineStore('main', {
state: () => {
......@@ -17,9 +20,12 @@ export const mainStore = defineStore('main', {
};
},
getters: {
getKeepPages (state) {
return state.keepPages
}
getKeepPages () {
return this.keepPages
},
// getTestStoreList () {
// return testStore().list // 返回另一个store的值
// }
},
actions: {
changeState (state) {
......@@ -46,7 +52,9 @@ export const mainStore = defineStore('main', {
changeKeepPages () { // 清空所有缓存,用一个不存在的值覆盖
this.keepPages = ['default'];
},
keepThisPage (page) { // 新增缓存页
keepThisPage () { // 新增缓存页
const $router = useRouter();
const page = $router.currentRoute.value.meta.name;
this.keepPages.push(page);
},
removeThisPage (page) { // 删除缓存页
......
......@@ -20,70 +20,36 @@
<script setup>
import { mainStore } from '@/store'
import Cookies from 'js-cookie'
import 'animate.css';
import icon_subscribed from '@images/icon-dingyue01@2x.png'
import MyButton from '@/components/MyButton/index.vue'
import { onMounted } from 'vue'
import { useGo, useReplace } from '@/hooks/useGo'
// 自定义按钮颜色样式
import { styleObject1, styleObject2 } from '@/settings/designSetting.js'
import $ from 'jquery';
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
import { Toast } from 'vant';
import { nextTick, onMounted, reactive, ref, watch } from 'vue'
import axios from '@/utils/axios';
import { wxInfo } from '@/utils/tools';
const $route = useRoute();
const $router = useRouter();
const go = useGo();
const replace = useReplace();
// TAG: keepAlive 缓存页面
const store = mainStore();
store.keepThisPage($route.meta.name);
// 滚动条判断
function hasScrollbar() {
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);
}
store.keepThisPage();
onMounted(() => {
// 判断微信授权状态,进入页面时未授权需要授权跳转
if (!Cookies.get('PHPSESSID')) {
$router.replace({
path: '/auth',
query: {
href: location.hash,
userType: 'c'
}
});
replace('/auth', { href: location.hash, userType: 'c' })
}
// 进入项目自动打开导航栏 微信浏览器 避免样式错位
window.history.pushState({}, "title", "#")
})
// 自定义按钮颜色样式
const styleObject1 = reactive({
backgroundColor: '#FFFFFF',
color: '#0B3A72',
borderColor: '#0B3A72'
})
const styleObject2 = reactive({
backgroundColor: '#F9D95C',
color: '#0B3A72',
borderColor: '#F9D95C'
})
const goVisit = () => { // 跳转爱心书籍页面
$router.push({
path: '/client/chooseBook'
});
go('/client/chooseBook')
Cookies.set('userType', 'visitor'); // 访客标识
}
const goSchool = () => { // 跳转选择幼儿园页面
$router.push({
path: '/client/chooseSchool'
});
go('/client/chooseSchool')
Cookies.set('userType', 'client'); // 客户标识
}
......@@ -95,47 +61,11 @@ const goSchool = () => { // 跳转选择幼儿园页面
// onBeforeRouteLeave(() => {
// clearInterval(interval); // 清除调用
// })
const cancelAuth = () => {
axios.get('/srv/?a=cancel_wx_auth', {
params: {
type: 'cancel'
}
})
.then(res => {
if (res.data.code === 1) {
Toast.success('操作成功')
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
}
</script>
<script>
import mixin from 'common/mixin'
import { mainStore } from '@/store'
import { storeToRefs } from 'pinia'
export default {
name: 'index',
mixins: [mixin.init],
data() {
return {
}
},
mounted() {
},
methods: {
}
}
</script>
......