index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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" @click="pfdClick(item)">
  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. import Vue from "vue";
  29. import { ImagePreview } from "vant";
  30. Vue.use(ImagePreview);
  31. export default {
  32. data() {
  33. return {
  34. isCorpWX:false,
  35. isWX:false,
  36. user: null,
  37. unreadNum:0,
  38. images: [
  39. // require('../../assets/img/index/banner_1.png'),
  40. require('../../assets/img/index/banner4.jpeg'),
  41. // require('../../assets/img/index/banner_3.png'),
  42. ],
  43. routers: [],
  44. key: 0,
  45. isSyncData: false
  46. };
  47. },
  48. created() {
  49. if(localStorage.userInfo) {
  50. this.user = JSON.parse(localStorage.userInfo)
  51. // 是否为钉钉同步
  52. this.isSyncData = this.user.timeType.syncDingding || this.user.timeType.syncFanwei;
  53. }
  54. },
  55. mounted() {
  56. //有错误信息,优先跳转到登录页面去
  57. if(window.location.href.indexOf('errorMsg') != '-1') {
  58. this.$router.push("/login");
  59. }
  60. var ua = navigator.userAgent.toLowerCase();
  61. if (ua.indexOf("wxwork") > 0) {
  62. this.isCorpWX = true;
  63. } else if (ua.indexOf("micromessenger") > 0) {
  64. this.isWX = true;
  65. }
  66. let that = this;
  67. //企业微信是从后台授权后跳转过来的
  68. if (this.isCorpWX) {
  69. //后台自动授权登录的用户
  70. if(window.location.href.indexOf('userId') != '-1') {
  71. let href = window.location.href;
  72. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  73. if (loginUserId.includes('#/')) {
  74. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  75. }
  76. that.getAccountInfo(loginUserId)
  77. } else {
  78. //存在一部分用户,没有绑定企业微信,进来后跳到登录页面,登录页面输入账号密码进来后不带userId
  79. if (this.user) {
  80. that.getAccountInfo(that.user.id);
  81. } else {
  82. that.$router.push("/login");
  83. }
  84. }
  85. } else {
  86. //其他情况,刷新用户信息
  87. if (localStorage.userInfo != null) {
  88. that.user = JSON.parse(localStorage.userInfo);
  89. that.getAccountInfo(that.user.id);
  90. }
  91. }
  92. let userss = JSON.parse(localStorage.userInfo)
  93. if(userss.isMobFirstLogin == 1 && userss.createTime[0] > '2022' && userss.roleName == '超级管理员') {
  94. // 第一次登陆显示
  95. this.previewPicture()
  96. }
  97. },
  98. components: {
  99. Footer
  100. },
  101. methods: {
  102. pfdClick(item) {
  103. if(item.name == '使用说明') {
  104. let url = 'http://celiang.oss-cn-hangzhou.aliyuncs.com/measurement/2022-01/18/75it6phpocqYFV1642488558220118.pdf'
  105. let name = '使用说明书'
  106. // 将要传过去的值
  107. this.previewPDF(url, name)
  108. }
  109. },
  110. // 预览pdf
  111. previewPDF(url, name) {
  112. this.$router.push({
  113. path: '/pdf',
  114. query: {
  115. url: '',
  116. name: name
  117. }
  118. })
  119. },
  120. // 图片预览
  121. previewPicture() {
  122. let that = this
  123. let arr = [
  124. 'https://mobworktime.ttkuaiban.com/upload/b9cf863819924106a65255ccffae446d.png',
  125. 'https://mobworktime.ttkuaiban.com/upload/65afcaed7ad84c51a309db69c888fe6c.png',
  126. 'https://mobworktime.ttkuaiban.com/upload/3452d33a68bb4092b04147e5482fd0e9.png',
  127. 'https://mobworktime.ttkuaiban.com/upload/af5b430f48b24b2683fb48a43deab98c.png',
  128. 'https://mobworktime.ttkuaiban.com/upload/b69779d86be44ef3a1d3585816fde5f3.png'
  129. ]
  130. ImagePreview({
  131. images: arr,
  132. startPosition: 0,
  133. showIndicators: true,
  134. closeable: true,
  135. onClose() {
  136. that.previewPictureClose()
  137. },
  138. });
  139. },
  140. // 处理关闭事件
  141. previewPictureClose() {
  142. this.$axios.post("/user/mobSkipGuidance", {
  143. })
  144. .then(res => {
  145. if(res.code == "ok") {
  146. let userss = JSON.parse(localStorage.userInfo)
  147. userss.isMobFirstLogin = 0
  148. localStorage.userInfo = JSON.stringify(userss);
  149. }
  150. }).catch(err=> {this.$toast.clear();});
  151. },
  152. tokefu(){
  153. wx.invoke('openThirdAppServiceChat', {
  154. }, function(res) {
  155. console.log('invoke',res);
  156. if (res.err_msg == "openThirdAppServiceChat:ok" || res.err_msg == "openThirdAppServiceChat:cancel") {
  157. }else{
  158. this.$toast.fail('请联系管理员添加客服');
  159. }
  160. }
  161. );
  162. },
  163. // 模块
  164. getModule() {
  165. if(this.user.userNameNeedTranslate == '1'){
  166. this.agentConfig()
  167. }
  168. if (this.user.company.packageEngineering == 1) {
  169. this.routers.push(
  170. {
  171. name: '专业审核',
  172. url: '/profession_review',
  173. icon: 'todo-list-o'
  174. });
  175. }
  176. var list = this.user.moduleList
  177. for (var i in list) {
  178. if(list[i].name == '工时报告') {
  179. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  180. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  181. // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
  182. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
  183. // }
  184. }
  185. if(list[i].name == '待办任务') {
  186. this.routers.push({
  187. name: '待办任务',
  188. url: '/task',
  189. icon: 'coupon-o'
  190. });
  191. }
  192. if(list[i].name == '项目报告审核') {
  193. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  194. }
  195. if(list[i].name == '项目管理') {
  196. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  197. }
  198. if(list[i].name == '导入日报审核') {
  199. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'completed'})
  200. }
  201. if(!this.isSyncData) {
  202. if(list[i].name == '请假管理') {
  203. this.routers.push({name: '请假管理',url: '/applyLeave',icon: 'notes-o'})
  204. // this.routers.push({name: '请假审批',url: '/exaLeave',icon: 'completed'})
  205. // this.routers.push({name: '出差管理',url: '/awayOffice',icon: 'completed'})
  206. }
  207. if(list[i].name == '出差管理') {
  208. this.routers.push({name: '出差管理',url: '/awayOffice',icon: 'logistics'})
  209. }
  210. }
  211. if(list[i].name == '费用报销') {
  212. this.routers.push({
  213. name: '费用报销',
  214. url: '/expense',
  215. icon: 'balance-list-o'
  216. });
  217. }
  218. }
  219. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  220. this.routers.push(
  221. {
  222. name: '部门审核',
  223. url: '/department_review',
  224. icon: 'todo-list-o'
  225. });
  226. }
  227. this.routers.push({
  228. name: '消息记录',
  229. url: '/msg',
  230. icon: 'todo-list-o',
  231. info: this.unreadNum
  232. });
  233. // 针对超级管理员加使用说明
  234. if(this.user.roleName == '超级管理员') {
  235. this.routers.push(
  236. {
  237. name: '使用说明',
  238. // url: '/',
  239. icon: 'todo-list-o'
  240. });
  241. }
  242. },
  243. // 获取企业微信参数
  244. agentConfig(){
  245. let curUrl = window.location.href.split('#')[0]
  246. this.$axios.post('/wxcorp/getCorpWXConfig',{
  247. url: curUrl,
  248. token: this.user.id
  249. }).then(res => {
  250. if(res.code == 'ok'){
  251. wx.config({
  252. beta: true,
  253. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  254. appId: res.data.appid, // 必填,公众号的唯一标识
  255. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  256. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  257. signature: res.data.sign, // 必填,签名,见附录1
  258. jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage','previewFile','getLocation','agentConfig']
  259. })
  260. let that = this
  261. wx.ready(function(){
  262. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  263. that.$axios.post('/wxcorp/getCorpWXAgentConfig', {
  264. url: curUrl,
  265. token: that.user.id
  266. }).then(res => {
  267. if(res.code == 'ok'){
  268. wx.agentConfig({
  269. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  270. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  271. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  272. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  273. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  274. jsApiList: ['selectExternalContact','openThirdAppServiceChat', 'openAppManage'], //必填,传入需要使用的接口名称
  275. success: function (result) {
  276. // console.log(result, '请求微信成功')
  277. // console.log(window, 'window')
  278. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  279. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  280. // that.kefuShow = true
  281. },
  282. fail: function (res) {
  283. // console.log('查看错误信息', res)
  284. if (res.errMsg.indexOf('function not exist') > -1) {
  285. alert('版本过低请升级')
  286. } else {
  287. // alert('agentConfig出错:'+res.errMsg);
  288. }
  289. },
  290. })
  291. }
  292. }).catch(err => {
  293. if (err.errMsg.indexOf('function not exist') > -1) {
  294. alert('版本过低请升级')
  295. }else {
  296. // alert(res.errMsg);
  297. }
  298. })
  299. });
  300. wx.error(function(res){
  301. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  302. // alert('wxConfig发生异常:'+JSON.stringify(res));
  303. // 企业第一次授权安装进入后会报not in reliable domain的错误,刷新后正常
  304. location.reload();
  305. });
  306. } else {
  307. // alert(''+res);
  308. }
  309. }).catch(err => {
  310. alert(err);
  311. })
  312. },
  313. //获取账户信息
  314. getAccountInfo(userId) {
  315. this.$axios.get('/user/loginByUserId', {params:{userId: userId}})
  316. .then(res => {
  317. // console.log(res);
  318. if (res.code == 'error') {
  319. localStorage.errorMsg = res.msg;
  320. //账号信息有问题,不能使用。
  321. this.$router.push("/error");
  322. } else {
  323. localStorage.userInfo = JSON.stringify(res.data);
  324. this.user = res.data;
  325. this.$refs.child.dealWith()
  326. this.key++
  327. this.getModule()
  328. this.getMessage();
  329. this.redirectIfNess();
  330. this.$forceUpdate()
  331. // this.bindIfNessary();
  332. }
  333. }).catch(err=> {
  334. alert('err=' + err);
  335. });
  336. },
  337. redirectIfNess() {
  338. var href = window.location.href;
  339. if (href.indexOf('path') > 0) {
  340. var path = href.split('path=')[1].split('&')[0];
  341. if (path == 'expense' || path == 'task') {
  342. this.$router.push(path);
  343. }
  344. }
  345. },
  346. bindIfNessary() {
  347. let href = window.location.href;
  348. var requestUrl = "";
  349. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  350. requestUrl = "/wxcorp/bindCorpWeiXin";
  351. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  352. requestUrl = "/wechat/bindWeiXin";
  353. }
  354. if (requestUrl.length > 0) {
  355. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  356. //会自动跳转到首页
  357. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  358. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  359. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  360. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  361. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  362. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  363. // console.log('urlRight=' + urlRight);
  364. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  365. //获取code
  366. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  367. if (code.indexOf('&state=1') > 0) {
  368. code = code.substring(0, code.indexOf('&state=1'));
  369. }
  370. //调用后台接口,注册用户
  371. // console.log('获取到code=='+code);
  372. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  373. .then(res => {
  374. // console.log(res);
  375. if (res == null) {
  376. this.$toast.fail('绑定失败');
  377. } else if(res.errcode != null) {
  378. //报错了
  379. console.log(res.errmsg);
  380. } else {
  381. //获取openId
  382. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  383. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  384. localStorage.userInfo = JSON.stringify(res.data);
  385. // console.log('绑定成功');
  386. this.user = res.data;
  387. window.location.href = '/#/my/center';
  388. }
  389. }
  390. }).catch(err=> {
  391. alert('err=' + err);
  392. });
  393. }
  394. }
  395. },
  396. //获取消息
  397. getMessage() {
  398. this.$axios.post("/information/list", {
  399. })
  400. .then(res => {
  401. if(res.code == "ok") {
  402. var list = res.data;
  403. this.unreadNum = list.filter(l=>l.checked==0).length;
  404. // console.log(this.unreadNum);
  405. }
  406. }).catch(err=> {this.$toast.clear();});
  407. },
  408. },
  409. activated(){
  410. this.getMessage()
  411. },
  412. };
  413. </script>
  414. <style lang="less" scoped>
  415. .swipe-img {
  416. img {
  417. width: 100%;
  418. height: 100%;
  419. }
  420. }
  421. .body {
  422. height: calc(100vh - 50px);
  423. position: relative;
  424. }
  425. .kefu{
  426. position: fixed;
  427. right: 35px;
  428. bottom: 120px;
  429. width: 36px;
  430. height: 36px;
  431. background-color: #fff;
  432. z-index: 1000;
  433. border-radius: 50%;
  434. img{
  435. margin: 4px;
  436. width: 28px;
  437. height: 28px;
  438. }
  439. }
  440. .tip {
  441. position: absolute;
  442. width: 100%;
  443. bottom: 5px;
  444. font-size: 14px;
  445. color: #8f8f8f;
  446. margin-top: 20px;
  447. text-align: center;
  448. line-height: 20px;
  449. }
  450. </style>