index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <div class="body">
  3. <van-swipe class="my-swipe" :autoplay="3000" :height="200" indicator-color="white">
  4. <van-swipe-item v-for="(item, index) in images" :key="index" class="swipe-img">
  5. <img :src="item"/>
  6. </van-swipe-item>
  7. </van-swipe>
  8. <van-grid :column-num="3">
  9. <van-grid-item v-for="(item,index) in routers" :key="index" :icon="item.icon" :text="item.name"
  10. :info="(item.name=='消息记录'&&unreadNum>0)?unreadNum:''"
  11. :to="item.url">
  12. </van-grid-item>
  13. </van-grid>
  14. <!-- <div class="tip" v-if="isCorpWX">
  15. 工时报表统计等更多功能,请从PC端企业微信进入
  16. </div> -->
  17. <!-- <van-icon v-if="isCorpWX" class="kefu" name="service-o" size="30" color="#20a0ff" @click="tokefu" /> -->
  18. <div v-if="isCorpWX" class="kefu" @click="tokefu"><img src="../../assets/icon/kefu.png" alt=""></div>
  19. <div class="tip" v-if="!isCorpWX">
  20. 体验报表统计等更多功能,尽在PC端<br>
  21. 网页用户访问http://worktime.ttkuaiban.com,钉钉用户直接从钉钉PC端进入工时管家
  22. </div>
  23. <Footer ref="child" :key="key"></Footer>
  24. </div>
  25. </template>
  26. <script>
  27. import Footer from "@/components/Footer";
  28. export default {
  29. data() {
  30. return {
  31. isCorpWX:false,
  32. isWX:false,
  33. user: '',
  34. unreadNum:0,
  35. images: [
  36. // require('../../assets/img/index/banner_1.png'),
  37. require('../../assets/img/index/banner4.jpeg'),
  38. // require('../../assets/img/index/banner_3.png'),
  39. ],
  40. routers: [],
  41. key: 0,
  42. };
  43. },
  44. created() {
  45. if(localStorage.userInfo) {
  46. this.user = JSON.parse(localStorage.userInfo)
  47. }
  48. },
  49. mounted() {
  50. // 手机上看控制台
  51. // if(this.user.companyName == '比基尼小镇'){
  52. // let consoleScript = document.createElement("script");
  53. // consoleScript.src = "https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js";
  54. // consoleScript.onload = function () {
  55. // new VConsole()
  56. // }
  57. // document.head.appendChild(consoleScript);
  58. // }
  59. //有错误信息,优先跳转到登录页面去
  60. if(window.location.href.indexOf('errorMsg') != '-1') {
  61. this.$router.push("/login");
  62. }
  63. var ua = navigator.userAgent.toLowerCase();
  64. if (ua.indexOf("wxwork") > 0) {
  65. this.isCorpWX = true;
  66. } else if (ua.indexOf("micromessenger") > 0) {
  67. this.isWX = true;
  68. }
  69. let that = this;
  70. //企业微信是从后台授权后跳转过来的
  71. if (this.isCorpWX) {
  72. if(window.location.href.indexOf('userId') != '-1') {
  73. let href = window.location.href;
  74. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  75. if (loginUserId.includes('#/')) {
  76. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  77. }
  78. that.getAccountInfo(loginUserId)
  79. } else {
  80. this.$router.push("/login");
  81. }
  82. } else {
  83. //其他情况,刷新用户信息
  84. if (localStorage.userInfo != null) {
  85. that.user = JSON.parse(localStorage.userInfo);
  86. that.getAccountInfo(that.user.id);
  87. }
  88. }
  89. },
  90. components: {
  91. Footer
  92. },
  93. methods: {
  94. tokefu(){
  95. wx.invoke('openThirdAppServiceChat', {
  96. }, function(res) {
  97. console.log('invoke',res);
  98. if (res.err_msg == "openThirdAppServiceChat:ok" || res.err_msg == "openThirdAppServiceChat:cancel") {
  99. }else{
  100. this.$toast.fail('请联系管理员添加客服');
  101. }
  102. }
  103. );
  104. },
  105. // 模块
  106. getModule() {
  107. if(this.user.userNameNeedTranslate == '1'){
  108. this.agentConfig()
  109. }
  110. if (this.user.company.packageEngineering == 1) {
  111. this.routers.push(
  112. {
  113. name: '专业审核',
  114. url: '/profession_review',
  115. icon: 'todo-list-o'
  116. });
  117. }
  118. var list = this.user.moduleList
  119. for (var i in list) {
  120. if(list[i].name == '工时报告') {
  121. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  122. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  123. // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
  124. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
  125. // }
  126. }
  127. if(list[i].name == '待办任务') {
  128. this.routers.push({
  129. name: '待办任务',
  130. url: '/task',
  131. icon: 'coupon-o'
  132. });
  133. }
  134. if(list[i].name == '项目报告审核') {
  135. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  136. }
  137. if(list[i].name == '项目管理') {
  138. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  139. }
  140. if(list[i].name == '导入日报审核') {
  141. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'completed'})
  142. }
  143. if(list[i].name == '费用报销') {
  144. this.routers.push({
  145. name: '费用报销',
  146. url: '/expense',
  147. icon: 'balance-list-o'
  148. });
  149. }
  150. }
  151. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  152. this.routers.push(
  153. {
  154. name: '部门审核',
  155. url: '/department_review',
  156. icon: 'todo-list-o'
  157. });
  158. }
  159. this.routers.push({
  160. name: '消息记录',
  161. url: '/msg',
  162. icon: 'todo-list-o',
  163. info: this.unreadNum
  164. });
  165. },
  166. // 获取企业微信参数
  167. agentConfig(){
  168. let curUrl = window.location.href.split('#')[0]
  169. this.$axios.post('/wxcorp/getCorpWXConfig',{
  170. url: curUrl,
  171. token: this.user.id
  172. }).then(res => {
  173. if(res.code == 'ok'){
  174. wx.config({
  175. beta: true,
  176. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  177. appId: res.data.appid, // 必填,公众号的唯一标识
  178. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  179. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  180. signature: res.data.sign, // 必填,签名,见附录1
  181. jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage','previewFile','getLocation','agentConfig']
  182. })
  183. let that = this
  184. wx.ready(function(){
  185. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  186. that.$axios.post('/wxcorp/getCorpWXAgentConfig', {
  187. url: curUrl,
  188. token: that.user.id
  189. }).then(res => {
  190. if(res.code == 'ok'){
  191. wx.agentConfig({
  192. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  193. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  194. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  195. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  196. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  197. jsApiList: ['selectExternalContact','openThirdAppServiceChat'], //必填,传入需要使用的接口名称
  198. success: function (result) {
  199. // console.log(result, '请求微信成功')
  200. // console.log(window, 'window')
  201. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  202. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  203. // that.kefuShow = true
  204. },
  205. fail: function (res) {
  206. // console.log('查看错误信息', res)
  207. if (res.errMsg.indexOf('function not exist') > -1) {
  208. alert('版本过低请升级')
  209. } else {
  210. // alert('agentConfig出错:'+res.errMsg);
  211. }
  212. },
  213. })
  214. }
  215. }).catch(err => {
  216. if (err.errMsg.indexOf('function not exist') > -1) {
  217. alert('版本过低请升级')
  218. }else {
  219. // alert(res.errMsg);
  220. }
  221. })
  222. });
  223. wx.error(function(res){
  224. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  225. // alert('wxConfig发生异常:'+JSON.stringify(res));
  226. // 企业第一次授权安装进入后会报not in reliable domain的错误,刷新后正常
  227. location.reload();
  228. });
  229. } else {
  230. // alert(''+res);
  231. }
  232. }).catch(err => {
  233. alert(err);
  234. })
  235. },
  236. //获取账户信息
  237. getAccountInfo(userId) {
  238. this.$axios.get('/user/loginByUserId', {params:{userId: userId}})
  239. .then(res => {
  240. // console.log(res);
  241. if (res.code == 'error') {
  242. localStorage.errorMsg = res.msg;
  243. //账号信息有问题,不能使用。
  244. this.$router.push("/error");
  245. } else {
  246. localStorage.userInfo = JSON.stringify(res.data);
  247. this.user = res.data;
  248. this.$refs.child.dealWith()
  249. this.key++
  250. this.getModule()
  251. this.getMessage();
  252. this.redirectIfNess();
  253. this.$forceUpdate()
  254. // this.bindIfNessary();
  255. }
  256. }).catch(err=> {
  257. alert('err=' + err);
  258. });
  259. },
  260. redirectIfNess() {
  261. var href = window.location.href;
  262. if (href.indexOf('path') > 0) {
  263. var path = href.split('path=')[1].split('&')[0];
  264. this.$router.push(path);
  265. }
  266. },
  267. bindIfNessary() {
  268. let href = window.location.href;
  269. var requestUrl = "";
  270. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  271. requestUrl = "/wxcorp/bindCorpWeiXin";
  272. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  273. requestUrl = "/wechat/bindWeiXin";
  274. }
  275. if (requestUrl.length > 0) {
  276. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  277. //会自动跳转到首页
  278. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  279. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  280. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  281. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  282. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  283. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  284. // console.log('urlRight=' + urlRight);
  285. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  286. //获取code
  287. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  288. if (code.indexOf('&state=1') > 0) {
  289. code = code.substring(0, code.indexOf('&state=1'));
  290. }
  291. //调用后台接口,注册用户
  292. // console.log('获取到code=='+code);
  293. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  294. .then(res => {
  295. // console.log(res);
  296. if (res == null) {
  297. this.$toast.fail('绑定失败');
  298. } else if(res.errcode != null) {
  299. //报错了
  300. console.log(res.errmsg);
  301. } else {
  302. //获取openId
  303. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  304. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  305. localStorage.userInfo = JSON.stringify(res.data);
  306. // console.log('绑定成功');
  307. this.user = res.data;
  308. window.location.href = '/#/my/center';
  309. }
  310. }
  311. }).catch(err=> {
  312. alert('err=' + err);
  313. });
  314. }
  315. }
  316. },
  317. //获取消息
  318. getMessage() {
  319. this.$axios.post("/information/list", {
  320. })
  321. .then(res => {
  322. if(res.code == "ok") {
  323. var list = res.data;
  324. this.unreadNum = list.filter(l=>l.checked==0).length;
  325. // console.log(this.unreadNum);
  326. }
  327. }).catch(err=> {this.$toast.clear();});
  328. },
  329. },
  330. activated(){
  331. this.getMessage()
  332. }
  333. };
  334. </script>
  335. <style lang="less" scoped>
  336. .swipe-img {
  337. img {
  338. width: 100%;
  339. height: 100%;
  340. }
  341. }
  342. .body {
  343. height: calc(100vh - 50px);
  344. position: relative;
  345. }
  346. .kefu{
  347. position: fixed;
  348. right: 35px;
  349. bottom: 120px;
  350. width: 36px;
  351. height: 36px;
  352. background-color: #fff;
  353. z-index: 1000;
  354. border-radius: 50%;
  355. img{
  356. margin: 4px;
  357. width: 28px;
  358. height: 28px;
  359. }
  360. }
  361. .tip {
  362. position: absolute;
  363. width: 100%;
  364. bottom: 5px;
  365. font-size: 14px;
  366. color: #8f8f8f;
  367. margin-top: 20px;
  368. text-align: center;
  369. line-height: 20px;
  370. }
  371. </style>