Commit 92ed03bc by zhangxw

分享逻辑调整

1 parent 2a3d8618
...@@ -39,3 +39,13 @@ export const SET_FREQ = (params) => { ...@@ -39,3 +39,13 @@ export const SET_FREQ = (params) => {
export const ADD_FENCE = (params) => { export const ADD_FENCE = (params) => {
return request(params, `${prefix}/fence/add`, "POST"); return request(params, `${prefix}/fence/add`, "POST");
}; };
// 获取分享id
export const GET_SHARE_ID = (params) => {
return request(params, `${prefix}/share/vehicle`);
};
// 校验分享时效性 是否可用
export const CHECK_SHARE = (params) => {
return request(params, `${prefix}/vehicle/sharedDetails`);
};
.icon-share {
position: absolute;
top: 20px;
right: 70px;
}
.tip {
margin-top: 105px;
text-align: center;
color: #fff;
font-size: 16px;
.fle {
display: inline-block;
width: 18px;
height: 22px;
vertical-align: middle;
}
.sharebtn {
display: inline-block;
width: 4px;
height: 4px;
margin: 1px;
background: #fff;
border-radius: 50%;
}
.sharebtn.middle {
width: 6px;
height: 6px;
margin: 0;
}
}
\ No newline at end of file \ No newline at end of file
...@@ -29,10 +29,10 @@ export default { ...@@ -29,10 +29,10 @@ export default {
let checkLoadedTimeoutId = ""; let checkLoadedTimeoutId = "";
const satelActive = ref(null); const satelActive = ref(null);
const roadActive = ref(null); const roadActive = ref(null);
const sharePage = ref(true); const sharePage = ref(false);
onMounted(() => {}); onMounted(() => {});
const initMap = (id) => { const initMap = (id) => {
// sharePage.value = localStorage.getItem("sharePage"); sharePage.value = JSON.parse(localStorage.getItem("sharePage"));
let check = () => { let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId); checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap; let AMap = window.AMap;
......
...@@ -44,6 +44,10 @@ export default { ...@@ -44,6 +44,10 @@ export default {
} }
}); });
} }
console.log(localStorage.getItem("sharePage"));
if (localStorage.getItem("sharePage")) {
routesArr.splice(routesArr.length - 1, 1);
}
await cb(); await cb();
}; };
filterTabs(() => { filterTabs(() => {
......
...@@ -73,6 +73,19 @@ ...@@ -73,6 +73,19 @@
</div> </div>
</div> </div>
</div> </div>
<van-overlay
:show="showOverlay"
@click="showOverlay = false"
:z-index="100000"
>
<span class="icon icon-share"></span>
<p class="tip">
点击右上角“&nbsp;<span class="fle"
><span class="sharebtn"></span><span class="sharebtn middle"></span
><span class="sharebtn"></span></span
>&nbsp;”转发/分享
</p>
</van-overlay>
</div> </div>
</template> </template>
...@@ -87,7 +100,13 @@ import wx from "wx"; ...@@ -87,7 +100,13 @@ import wx from "wx";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { Dialog, Toast } from "vant"; import { Dialog, Toast } from "vant";
import "vant/es/toast/style"; import "vant/es/toast/style";
import { GET_ALL_CAR_LIST, GET_CAR_LOCATION_INFO } from "@/api/index"; import moment from "@/utils/moment";
import {
GET_ALL_CAR_LIST,
GET_CAR_LOCATION_INFO,
GET_SHARE_ID,
CHECK_SHARE,
} from "@/api/index";
export default defineComponent({ export default defineComponent({
name: "IndexPage", name: "IndexPage",
components: { components: {
...@@ -101,8 +120,7 @@ export default defineComponent({ ...@@ -101,8 +120,7 @@ export default defineComponent({
const finished = ref(false); const finished = ref(false);
const list = ref([]); const list = ref([]);
const carItem = ref(null); const carItem = ref(null);
const loginUserId = ref(""); const isShareDead = ref(false);
const isShareDead = ref(1);
const carInfoList = ref([]); const carInfoList = ref([]);
const route = useRoute(); const route = useRoute();
const routeQuery = ref(null); const routeQuery = ref(null);
...@@ -111,7 +129,10 @@ export default defineComponent({ ...@@ -111,7 +129,10 @@ export default defineComponent({
const mapIsUploaded = ref(false); const mapIsUploaded = ref(false);
const store = useStore(); const store = useStore();
const ISLOADING = computed(() => store.state.LOADING); const ISLOADING = computed(() => store.state.LOADING);
const showOverlay = ref(false);
let isSharePage = false;
let map = undefined; let map = undefined;
let _timeoutId = undefined;
const refreshCb = () => { const refreshCb = () => {
if (map && carItem.value) { if (map && carItem.value) {
map && map.clearMap(); map && map.clearMap();
...@@ -124,12 +145,6 @@ export default defineComponent({ ...@@ -124,12 +145,6 @@ export default defineComponent({
// 被分享者打开直接获取车辆定位数据 // 被分享者打开直接获取车辆定位数据
routeQuery.value = route.query; routeQuery.value = route.query;
if (newVal && routeQuery.value.sn) { if (newVal && routeQuery.value.sn) {
if (route.query.token) {
localStorage.setItem("token", route.query.token);
}
if (route.query.sharePage) {
localStorage.setItem("sharePage", true);
}
carItem.value = { carItem.value = {
sns: routeQuery.value.sn, sns: routeQuery.value.sn,
ownerName: ownerName:
...@@ -138,15 +153,53 @@ export default defineComponent({ ...@@ -138,15 +153,53 @@ export default defineComponent({
: routeQuery.value.ownerName, : routeQuery.value.ownerName,
vin: routeQuery.value.vin == "null" ? "--" : routeQuery.value.vin, vin: routeQuery.value.vin == "null" ? "--" : routeQuery.value.vin,
}; };
if (route.query.token) {
localStorage.setItem("token", route.query.token);
}
if (JSON.parse(route.query.sharePage)) {
localStorage.setItem("sharePage", JSON.parse(route.query.sharePage));
// 获取分享id
GET_SHARE_ID({ vehicleId: Number(routeQuery.value.id) }).then(
(res) => {
if (res.code == 200) {
// 校验分享链接是否有效
CHECK_SHARE({ shareId: res.data }).then((v) => {
if (v.code == 200) {
if (
v.data &&
v.data.setting &&
v.data.setting.enableStatus !== 1
) {
Dialog({ message: "该分享无效,请启用后使用" });
} else if (
v.data &&
v.data.setting &&
moment().isAfter(moment(v.data.setting.expirationDate))
) {
isShareDead.value = true;
Dialog({ message: "该分享已失效" });
} else {
getCarInfo(carItem.value); getCarInfo(carItem.value);
// 校验分享时效性
checkIsShareDead(res.data);
}
}
});
}
}
);
}
} }
}); });
onMounted(() => { onMounted(() => {
getCarList(); localStorage.removeItem("sharePage");
if (route.query.token) { if (route.query.token) {
localStorage.setItem("token", route.query.token); localStorage.setItem("token", route.query.token);
} }
localStorage.removeItem("sharePage"); if (route.query.sharePage) {
localStorage.setItem("sharePage", JSON.parse(route.query.sharePage));
isSharePage = JSON.parse(route.query.sharePage);
}
AMapLoader.load({ AMapLoader.load({
key: CONSTANT.MAP_KEY, key: CONSTANT.MAP_KEY,
version: "1.4.8", version: "1.4.8",
...@@ -156,6 +209,27 @@ export default defineComponent({ ...@@ -156,6 +209,27 @@ export default defineComponent({
mapContentRefs.value.initMap("container"); mapContentRefs.value.initMap("container");
}); });
}); });
const checkIsShareDead = (id) => {
if (_timeoutId) {
clearTimeout(_timeoutId);
}
_timeoutId = setTimeout(() => {
CHECK_SHARE({ shareId: id }).then((v) => {
if (v.code == 200) {
if (
(v.data && v.data.setting && v.data.setting.enableStatus !== 1) ||
(v.data &&
v.data.setting &&
moment().isAfter(moment(v.data.setting.expirationDate)))
) {
isShareDead.value = true;
} else {
checkIsShareDead();
}
}
});
}, 1000 * 60 * 5);
};
const isUploaded = (data) => { const isUploaded = (data) => {
mapIsUploaded.value = data; mapIsUploaded.value = data;
}; };
...@@ -327,6 +401,9 @@ export default defineComponent({ ...@@ -327,6 +401,9 @@ export default defineComponent({
carFenceBtn && carFenceBtn.classList.add("disabled"); carFenceBtn && carFenceBtn.classList.add("disabled");
} }
if (isSharePage) {
shareBtn && shareBtn.classList.add("disabled");
}
// 点击GPS // 点击GPS
GPSBtn && GPSBtn &&
(GPSBtn.onclick = () => { (GPSBtn.onclick = () => {
...@@ -444,7 +521,7 @@ export default defineComponent({ ...@@ -444,7 +521,7 @@ export default defineComponent({
// 电子围栏 // 电子围栏
(carFenceBtn && carFenceBtn).onclick = () => { (carFenceBtn && carFenceBtn).onclick = () => {
if (loginUserId.value || item.source == 0) { if (item.source == 0) {
return; return;
} else { } else {
wx.miniProgram.navigateTo({ wx.miniProgram.navigateTo({
...@@ -454,9 +531,10 @@ export default defineComponent({ ...@@ -454,9 +531,10 @@ export default defineComponent({
}; };
// 分享找车 // 分享找车
shareBtn.onclick = () => { shareBtn.onclick = () => {
wx.miniProgram.navigateTo({ if (isSharePage) {
url: `../../mapPackage/pages/findCar?sn=${item.sn}&tabItem=share&source=${item.source}&locationType=${item.locationType}`, return;
}); }
showOverlay.value = true;
}; };
//点击车辆打开信息窗体 //点击车辆打开信息窗体
marker.on("click", () => { marker.on("click", () => {
...@@ -471,7 +549,7 @@ export default defineComponent({ ...@@ -471,7 +549,7 @@ export default defineComponent({
return marker; return marker;
}; };
const check = (cb) => { const check = (cb) => {
if (loginUserId.value && isShareDead.value) { if (isShareDead.value) {
Toast("该分享已失效"); Toast("该分享已失效");
return; return;
} }
...@@ -514,7 +592,6 @@ export default defineComponent({ ...@@ -514,7 +592,6 @@ export default defineComponent({
list, list,
getCarList, getCarList,
getCarInfo, getCarInfo,
loginUserId,
check, check,
carInfoList, carInfoList,
carItem, carItem,
...@@ -524,12 +601,14 @@ export default defineComponent({ ...@@ -524,12 +601,14 @@ export default defineComponent({
mapIsUploaded, mapIsUploaded,
routeQuery, routeQuery,
ISLOADING, ISLOADING,
showOverlay,
}; };
}, },
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "@/assets/css/share.scss";
.index-map { .index-map {
position: relative; position: relative;
} }
......
...@@ -112,34 +112,5 @@ export default defineComponent({ ...@@ -112,34 +112,5 @@ export default defineComponent({
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.icon-share { @import "@/assets/css/share.scss";
position: absolute;
top: 20px;
right: 65px;
}
.tip {
margin-top: 105px;
text-align: center;
color: #fff;
font-size: 16px;
.fle {
display: inline-block;
width: 18px;
height: 22px;
vertical-align: middle;
}
.sharebtn {
display: inline-block;
width: 4px;
height: 4px;
margin: 1px;
background: #fff;
border-radius: 50%;
}
.sharebtn.middle {
width: 6px;
height: 6px;
margin: 0;
}
}
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!