index.vue 23 KB

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