|
|
@@ -49,12 +49,43 @@ import ItemBanner from "../../../components/banner/itemBanner";
|
|
|
import {isMediaView} from "@/until/mediaView";
|
|
|
import {apiMap, baseUrl} from "~/map/apiMap";
|
|
|
import BigTitle from "~/components/public/bigTitle.vue";
|
|
|
+import {toNumber,isEmpty} from "../../../until/typeTool";
|
|
|
|
|
|
export default {
|
|
|
name: "itemIndex",
|
|
|
components: {BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
|
|
|
props:['uLang','pType', 'pInfo'],
|
|
|
-
|
|
|
+ async asyncData(ctx){
|
|
|
+ // 判断是否有id,如果有id则请求数据,否则则不请求数据
|
|
|
+ let err,res;
|
|
|
+ let id = ctx.query.id;
|
|
|
+ // id转数字
|
|
|
+ let url = baseUrl + apiMap.productInfo.path ;
|
|
|
+ if(!toNumber(id)){
|
|
|
+ return ctx.redirect(`/product`);
|
|
|
+ }
|
|
|
+ console.log(`开始获取产品 id:${id}`);
|
|
|
+ url += `/${id}`;
|
|
|
+ [err,res] = await handle(axios.get(url));
|
|
|
+ if(err){
|
|
|
+ // 加载失败,返回至产品页面
|
|
|
+ console.log(`查询产品数据失败`);
|
|
|
+ ctx.redirect(`/product`);
|
|
|
+ return {}
|
|
|
+ }
|
|
|
+ let result = res.data;
|
|
|
+ if(result.code === 1){
|
|
|
+ // console.log(result.data);
|
|
|
+ return {
|
|
|
+ productDetail:result.data,
|
|
|
+ type: result.data.type_key,
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ console.log(`查询产品数据失败,服务器异常`);
|
|
|
+ ctx.redirect(`/product`);
|
|
|
+ }
|
|
|
+ return {}
|
|
|
+ },
|
|
|
data(){
|
|
|
return {
|
|
|
langType: langMap.lang,
|
|
|
@@ -70,16 +101,24 @@ export default {
|
|
|
},
|
|
|
beforeMount() {
|
|
|
console.log(this.pInfo);
|
|
|
- this.productDetail = this.pInfo;
|
|
|
- console.log(this.productDetail.detail)
|
|
|
- console.log(this.productDetail.image)
|
|
|
+ if(isEmpty(this.productDetail) && isEmpty(this.pInfo)){
|
|
|
+ console.log('没有数据');
|
|
|
+ return this.$router.push('/product');
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isEmpty(this.productDetail)){
|
|
|
+ this.productDetail = this.pInfo;
|
|
|
+ }
|
|
|
this.productDetail.detail = unescape(this.productDetail.detail);
|
|
|
},
|
|
|
mounted() {
|
|
|
- console.log(this.pType);
|
|
|
- console.log(this.type);
|
|
|
+ // console.log(this.pType);
|
|
|
+ // console.log(this.type);
|
|
|
this.isPhone = isMediaView(0,1024);
|
|
|
- this.type = this.pType;
|
|
|
+ if(!isEmpty(this.type)){
|
|
|
+ this.type = this.pType;
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
methods:{
|
|
|
getLangText(str) {
|