zt il y a 9 mois
Parent
commit
e6cf348dac

+ 5 - 1
src/pages/cityDangerReport/add.vue

@@ -128,6 +128,7 @@ export default {
     };
   },
   methods: {
+
     async addForm() {
       console.log(this.fileList);
       console.log(this.form);
@@ -223,6 +224,9 @@ export default {
     },
   },
   mounted() {
+        console.log('this.$route.params', this.$route.params, this.$route.params.openId)
+        // alert('openId'+this.$route.params.openId)
+        this.form.createdBy = this.$route.params.openId
     if (this.$route.query.id) {
       this.getTroubleDetail();
     }
@@ -307,4 +311,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 117 - 48
src/pages/cityDangerReport/index.vue

@@ -4,11 +4,12 @@
     <!--vuetop-->
     <div class="morebox1 response">
       <div class="flex2 response flex justify-end">
-        <div class="text3" @click="$router.push('/addcityDangerReport')">
+        <div class="text3" @click="$router.push( { name: 'addcityDangerReport', params: { openId: search.createdBy }})">
           新增 <van-icon name="add" />
         </div>
       </div>
-      <van-list
+
+        <van-list
         v-model="isUpLoading"
         :finished="upFinished"
         :immediate-check="false"
@@ -36,56 +37,124 @@
   </div>
 </template>
 <script>
-import { listForAppTrouble } from "@/service/api_company.js";
+import { listForAppTrouble } from '@/service/api_company.js'
+import { Toast } from 'vant'
+import { getInitialCode, getUserInfo, fetchUserAccessToken } from '@/common/js/api_lingxi'
 export default {
-  data() {
-    return {
-      isUpLoading: false,
-      isDownLoading: false,
-      upFinished: false,
-      reportList: [],
-      search: {
-        pageNum: 1,
-        pageSize: "10",
-        createdBy: "10008611",
-      },
-    };
-  },
-  mounted() {
-      console.log('this.$route.params',this.$route.params,this.$route.params.openId)
-      // alert('openId'+this.$route.params.openId)
-      this.search.createdBy=this.$route.params.openId
-      // alert('this.search.createdBy'+this.search.createdBy)
-      this.getList();
-  },
-  methods: {
-    toDetail(id) {
-      this.$router.push("/addcityDangerReport?id=" + id);
-    },
-    async getList() {
-      listForAppTrouble(this.search).then((res) => {
-        if (res.data.rows.length) {
-          this.isDownLoading = false;
-          this.reportList.push(...res.data.rows);
-          this.isUpLoading = false;
-          if (this.reportList.length >= res.data.total) {
-            this.upFinished = true;
-          }
-        } else {
-          this.reportList = [];
-          this.isDownLoading = false;
-          this.isUpLoading = false;
-          this.upFinished = true;
+    data() {
+        return {
+            isUpLoading: false,
+            isDownLoading: false,
+            upFinished: false,
+            reportList: [],
+            search: {
+                pageNum: 1,
+                pageSize: '10',
+                createdBy: '10008611'
+            },
+            appId: 'B1334087658781568',
+            requestCode: '',
+            userAccessToken: ''
         }
-      });
     },
-    onLoadList() {
-      this.search.pageNum++;
-      this.isDownLoading = false;
-      this.getList();
+    mounted() {
+        // console.log('this.$route.params', this.$route.params, this.$route.params.openId)
+        // this.search.createdBy = this.$route.params.openId
+        // this.getList()
+        // alert('开始获取灵锡用户id')
+        this.getInitCode()
     },
-  },
-};
+    methods: {
+        async getInitCode() {
+            getInitialCode().then((res) => {
+                // alert('getInitialCode==>' + JSON.stringify(res))
+                this.initCode = res.data.initCode
+                // alert('initCode==>' + this.initCode)
+                this.handleAuthorization()
+            })
+        },
+        handleAuthorization() {
+             // alert(this.initCode)
+            const _this = this
+            ls.ready(function() {
+                ls.userAuth({
+                    appId: _this.appId // 从开放平台申请到的 appId
+                }, function(res) {
+                    // alert('res:' + JSON.stringify(res))
+                    if (res.code === 200) {
+                        // // alert('requestCode:' + res.data.requestCode)
+                        const reqData = {
+                            requestCode: res.data.requestCode
+                        }
+                        fetchUserAccessToken(reqData).then(res => {
+                            // alert('获取用户访问令牌——:' + res)
+                            getUserInfo({ userAccessToken: res }).then((res) => {
+                                // alert('用户信息——:' + JSON.stringify(res))
+                                // alert('用户信息1——:' + res.openId)
+                                // eslint-disable-next-line standard/object-curly-even-spacing
+                                // _this.$router.push({ name: urlname, params: { openId: res.openId, realName: res.realName }})
+                                // Toast('登录成功')
+
+                                _this.search.createdBy = res.openId
+                                // 执行下一步
+                                _this.getList()
+                            }).catch(e => {
+                                Toast(e)
+                            })
+                        })
+                    } else if (res.code === 9005) {
+                        // 认证失败或登录失败
+                        // console.log('认证失败或登录失败')
+                        // alert('认证失败或登录失败')
+                        // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
+                    } else {
+                        // 其余情况
+                        // alert('userAuth error')
+                        // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
+                    }
+                })
+            })
+
+            // 失败回调
+            ls.error(function(res) {
+                // 错误处理
+                // alert('失败回调')
+            })
+
+            ls.config({
+                debug: false, // 开发时建议把调试模式开启
+                appId: this.appId, // 从开放平台申请到的 appId
+                initCode: this.initCode // 从业务方自己后台请求到 initCode
+            })
+        },
+        // ===上面是灵锡用的===========================================================================
+        toDetail(id) {
+            this.$router.push('/addcityDangerReport?id=' + id)
+        },
+        async getList() {
+            listForAppTrouble(this.search).then((res) => {
+                if (res.data.rows.length) {
+                    this.isDownLoading = false
+                    this.reportList.push(...res.data.rows)
+                    this.isUpLoading = false
+                    if (this.reportList.length >= res.data.total) {
+                        this.upFinished = true
+                    }
+                } else {
+                    this.reportList = []
+                    this.isDownLoading = false
+                    this.isUpLoading = false
+                    this.upFinished = true
+                }
+            })
+        },
+        onLoadList() {
+            this.search.pageNum++
+            this.isDownLoading = false
+            this.getList()
+        }
+    }
+}
 </script>
 c
 <style lang="scss">

+ 9 - 8
src/pages/citySafeNotic/detail.vue

@@ -21,12 +21,12 @@ export default {
     data() {
         return {
             detail: {},
-            annex: [],
-            search: {
-                pageNum: '1',
-                createdBy: 'smx_h5_userId',
-                pageSize: '10'
-            }
+            annex: []
+            // search: {
+            //     pageNum: '1',
+            //     createdBy: 'xxxxx',
+            //     pageSize: '10'
+            // }
         }
     },
     mounted() {
@@ -38,9 +38,10 @@ export default {
             // window.open(url, "_blank");
         },
         async getNoticeById() {
+            // alert('createdBy:' + this.$route.params.openId + '===>' + this.$route.params.id + '==>' + this.$route.params)
             const { data } = await getNoticeById({
-                id: this.$route.query.id,
-                createdBy: 'smx_h5_userId'
+                id: this.$route.params.id,
+                createdBy: this.$route.params.openId
             })
             this.detail = data
             this.annex = JSON.parse(data.annex)

+ 77 - 8
src/pages/citySafeNotic/index.vue

@@ -42,6 +42,8 @@
 </template>
 <script>
 import { listForApp } from '@/service/api_company.js'
+import { Toast } from 'vant'
+import { getInitialCode, getUserInfo, fetchUserAccessToken } from '@/common/js/api_lingxi'
 export default {
     data() {
         return {
@@ -54,18 +56,82 @@ export default {
                 pageNum: 1,
                 pageSize: '10',
                 createdBy: 'smx_h5_userId'
-            }
+            },
+            appId: 'B1334087658781568',
+            requestCode: '',
+            userAccessToken: ''
         }
     },
     mounted() {
-        console.log('this.$route.params',this.$route.params,this.$route.params.openId)
-        alert('openId'+this.$route.params.openId)
-        this.search.createdBy=this.$route.params.openId
-        // alert('this.search.createdBy'+this.search.createdBy)
-
-        this.getList()
+        // console.log('this.$route.params',this.$route.params,this.$route.params.openId)
+        // this.search.createdBy=this.$route.params.openId
+        // this.getList()
+        this.getInitCode()
     },
     methods: {
+        async getInitCode() {
+            getInitialCode().then((res) => {
+                // alert('getInitialCode==>' + JSON.stringify(res))
+                this.initCode = res.data.initCode
+                // alert('initCode==>' + this.initCode)
+                this.handleAuthorization()
+            })
+        },
+        handleAuthorization() {
+            // // alert(this.initCode)
+            const _this = this
+            ls.ready(function() {
+                ls.userAuth({
+                    appId: _this.appId // 从开放平台申请到的 appId
+                }, function(res) {
+                    // alert('res:' + JSON.stringify(res))
+                    if (res.code === 200) {
+                        // // alert('requestCode:' + res.data.requestCode)
+                        const reqData = {
+                            requestCode: res.data.requestCode
+                        }
+                        fetchUserAccessToken(reqData).then(res => {
+                            // alert('获取用户访问令牌——:' + res)
+                            getUserInfo({ userAccessToken: res }).then((res) => {
+                                // alert('用户信息——:' + JSON.stringify(res))
+                                // alert('用户信息2——:' + res.openId)
+                                // eslint-disable-next-line standard/object-curly-even-spacing
+                                // _this.$router.push({ name: urlname, params: { openId: res.openId, realName: res.realName }})
+                                // Toast('登录成功')
+
+                                _this.search.createdBy = res.openId
+                                // 执行下一步
+                                _this.getList()
+                            }).catch(e => {
+                                Toast(e)
+                            })
+                        })
+                    } else if (res.code === 9005) {
+                        // 认证失败或登录失败
+                        // console.log('认证失败或登录失败')
+                        // alert('认证失败或登录失败')
+                        // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
+                    } else {
+                        // 其余情况
+                        // alert('userAuth error')
+                        // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
+                    }
+                })
+            })
+
+            // 失败回调
+            ls.error(function(res) {
+                // 错误处理
+                // alert('失败回调')
+            })
+
+            ls.config({
+                debug: false, // 开发时建议把调试模式开启
+                appId: this.appId, // 从开放平台申请到的 appId
+                initCode: this.initCode // 从业务方自己后台请求到 initCode
+            })
+        },
+        // ===上面是灵锡用的===========================================================================
         getTabs(e) {
             console.log(e)
             this.search.isRead = e == '全部' ? '' : e
@@ -77,7 +143,10 @@ export default {
             this.getList()
         },
         toDetail(id) {
-            this.$router.push('/citySafeNoticDetail?id=' + id)
+            // alert('toDetail:' + id + '==>' + this.search.createdBy)
+
+            // eslint-disable-next-line standard/object-curly-even-spacing
+            this.$router.push({ name: 'citySafeNoticDetail', params: { openId: this.search.createdBy, id: id }})
         },
         async getList() {
             listForApp(this.search).then((res) => {

+ 2 - 2
src/router/index.js

@@ -36,7 +36,7 @@ const router = new Router({
         },
         {
             path: '/citySafeNoticDetail',
-            name: 'citySafeNotic',
+            name: 'citySafeNoticDetail',
             meta: {
                 title: '城市安全通知公告'
             },
@@ -518,7 +518,7 @@ const router = new Router({
 // });
 
 // 路由守卫 拦截
-const whiteList = ['citySafeNoticBefore','cityDangerReportBefore','vistiorRegistration', 'login', 'register', 'QRcode', 'todo', 'webView', 'registerbycpyinfo', 'cityDangerReport', `addcityDangerReport`,'citySafeNotic'] // 路由守卫白名单
+const whiteList = ['citySafeNoticDetail','citySafeNoticBefore','cityDangerReportBefore','vistiorRegistration', 'login', 'register', 'QRcode', 'todo', 'webView', 'registerbycpyinfo', 'cityDangerReport', `addcityDangerReport`,'citySafeNotic'] // 路由守卫白名单
 
 router.beforeEach((to, from, next) => {
     /* 路由发生变化修改页面title */