index.vue 18 KB

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