Commit 92ed03bc by zhangxw

分享逻辑调整

1 parent 2a3d8618
......@@ -39,3 +39,13 @@ export const SET_FREQ = (params) => {
export const ADD_FENCE = (params) => {
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
......@@ -29,10 +29,10 @@ export default {
let checkLoadedTimeoutId = "";
const satelActive = ref(null);
const roadActive = ref(null);
const sharePage = ref(true);
const sharePage = ref(false);
onMounted(() => {});
const initMap = (id) => {
// sharePage.value = localStorage.getItem("sharePage");
sharePage.value = JSON.parse(localStorage.getItem("sharePage"));
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap;
......
......@@ -44,6 +44,10 @@ export default {
}
});
}
console.log(localStorage.getItem("sharePage"));
if (localStorage.getItem("sharePage")) {
routesArr.splice(routesArr.length - 1, 1);
}
await cb();
};
filterTabs(() => {
......
......@@ -73,6 +73,19 @@
</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>
</template>
......@@ -87,7 +100,13 @@ import wx from "wx";
import { useRoute } from "vue-router";
import { Dialog, Toast } from "vant";
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({
name: "IndexPage",
components: {
......@@ -101,8 +120,7 @@ export default defineComponent({
const finished = ref(false);
const list = ref([]);
const carItem = ref(null);
const loginUserId = ref("");
const isShareDead = ref(1);
const isShareDead = ref(false);
const carInfoList = ref([]);
const route = useRoute();
const routeQuery = ref(null);
......@@ -111,7 +129,10 @@ export default defineComponent({
const mapIsUploaded = ref(false);
const store = useStore();
const ISLOADING = computed(() => store.state.LOADING);
const showOverlay = ref(false);
let isSharePage = false;
let map = undefined;
let _timeoutId = undefined;
const refreshCb = () => {
if (map && carItem.value) {
map && map.clearMap();
......@@ -124,12 +145,6 @@ export default defineComponent({
// 被分享者打开直接获取车辆定位数据
routeQuery.value = route.query;
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 = {
sns: routeQuery.value.sn,
ownerName:
......@@ -138,15 +153,53 @@ export default defineComponent({
: routeQuery.value.ownerName,
vin: routeQuery.value.vin == "null" ? "--" : routeQuery.value.vin,
};
getCarInfo(carItem.value);
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);
// 校验分享时效性
checkIsShareDead(res.data);
}
}
});
}
}
);
}
}
});
onMounted(() => {
getCarList();
localStorage.removeItem("sharePage");
if (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({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
......@@ -156,6 +209,27 @@ export default defineComponent({
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) => {
mapIsUploaded.value = data;
};
......@@ -327,6 +401,9 @@ export default defineComponent({
carFenceBtn && carFenceBtn.classList.add("disabled");
}
if (isSharePage) {
shareBtn && shareBtn.classList.add("disabled");
}
// 点击GPS
GPSBtn &&
(GPSBtn.onclick = () => {
......@@ -444,7 +521,7 @@ export default defineComponent({
// 电子围栏
(carFenceBtn && carFenceBtn).onclick = () => {
if (loginUserId.value || item.source == 0) {
if (item.source == 0) {
return;
} else {
wx.miniProgram.navigateTo({
......@@ -454,9 +531,10 @@ export default defineComponent({
};
// 分享找车
shareBtn.onclick = () => {
wx.miniProgram.navigateTo({
url: `../../mapPackage/pages/findCar?sn=${item.sn}&tabItem=share&source=${item.source}&locationType=${item.locationType}`,
});
if (isSharePage) {
return;
}
showOverlay.value = true;
};
//点击车辆打开信息窗体
marker.on("click", () => {
......@@ -471,7 +549,7 @@ export default defineComponent({
return marker;
};
const check = (cb) => {
if (loginUserId.value && isShareDead.value) {
if (isShareDead.value) {
Toast("该分享已失效");
return;
}
......@@ -514,7 +592,6 @@ export default defineComponent({
list,
getCarList,
getCarInfo,
loginUserId,
check,
carInfoList,
carItem,
......@@ -524,12 +601,14 @@ export default defineComponent({
mapIsUploaded,
routeQuery,
ISLOADING,
showOverlay,
};
},
});
</script>
<style lang="scss" scoped>
@import "@/assets/css/share.scss";
.index-map {
position: relative;
}
......
......@@ -112,34 +112,5 @@ export default defineComponent({
});
</script>
<style lang="scss" scoped>
.icon-share {
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;
}
}
@import "@/assets/css/share.scss";
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!