index.vue 22 KB

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