shrnewlightapp_main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /* jshint esversion: 6 */
  2. //兼容部分安卓机型globalthis报错
  3. !(function(t){
  4. function e(){
  5. var e = this || self;
  6. (e.globalThis = e), delete t.prototype._T_;
  7. }
  8. "object" != typeof globalThis && (this ? e() : (t.defineProperty(t.prototype, "_T_", {
  9. configurable: !0,
  10. get: e,
  11. }), _T_))
  12. })(Object);
  13. //end
  14. var app = new Vue({
  15. el: '#app',
  16. data: {
  17. originData: [], // 所有权限项 需要拿到所有权限项 然后根据 localstorage 中的常用 number 数组 初始化 shrCommonlyUsed
  18. value: "",
  19. shrCommonlyUsed: [], // 常用 的所有数据
  20. originCategoricalDate:[], // 源数据 从服务器请求来的数据
  21. categoricalDate: [], // 搜索过滤后的数据
  22. title:"简体中文",
  23. bannerUrl:"/mbos/store/4000148/shrnewlightapp/banner.png",
  24. showChangeLan: true,
  25. search:"",
  26. versionError: false,
  27. signAgreement: false, //展示声明协议内容
  28. agreements: [], //声明协议
  29. showText: false,
  30. agreementText: '',
  31. isAllowVersion: false //8.8.0.0以上版本出现是否同意隐私声明弹窗
  32. },
  33. mounted: function () {
  34. const _this = this
  35. const usedStorage = JSON.parse(window.localStorage.getItem("shrCommonlyUsed")) || []
  36. var isYunZhiJia = window.navigator.userAgent.match(/Qing\/.*;(iOS|iPhone|Android).*/) ? true : false;
  37. var isYzjDesktop = window.navigator.userAgent.match(/.*Qing\/.*/) ? true : false;
  38. if(isYunZhiJia || isYzjDesktop){
  39. _this.showChangeLan = false;
  40. }
  41. setTimeout(() => {
  42. _this.initsHRVersion()
  43. _this.search = localeResource.search;
  44. _this.getAgreementInfo();
  45. mbos.eas.invokeScript({
  46. name: "commonOSFservice",
  47. param: ['getLightAppListService', JSON.stringify({})],
  48. success: function (res) {
  49. if (res && res.length) {
  50. _this.originCategoricalDate = res
  51. _this.categoricalDate = res
  52. //对分组轻应用进行排序
  53. _this.categoricalDate.forEach(item => {
  54. item.children = item.children.sort((a,b)=>{
  55. a.index = a.index || 0;
  56. b.index = b.index || 0;
  57. if(a.index && b.index){
  58. return a.index - b.index;
  59. }
  60. })
  61. });
  62. _this.originData = res.reduce((acc, item)=> acc.concat(item.children), [])
  63. _this.shrCommonlyUsed = usedStorage.map((number)=>{
  64. return _this.originData.find((item)=> item.number === number)
  65. }).filter(Boolean)
  66. window.localStorage.setItem("shrCommonlyUsed", JSON.stringify(_this.shrCommonlyUsed.map(({number})=> number)))
  67. }
  68. },
  69. error: function (e) {
  70. console.log(e);
  71. }
  72. })
  73. window.addEventListener('pageshow', function(){
  74. _this.getAgreementInfo();
  75. });
  76. if(easContext.locale === 'en_US'){
  77. _this.bannerUrl = "/mbos/store/4000148/shrnewlightapp/en_banner.png"
  78. }else{
  79. _this.bannerUrl = "/mbos/store/4000148/shrnewlightapp/banner.png"
  80. }
  81. })
  82. },
  83. methods: {
  84. onchange(e) {
  85. const value = e.target.value
  86. this.categoricalDate = this.originCategoricalDate.map((item)=> (
  87. {
  88. id: item.id,
  89. name: item.name,
  90. number: item.number,
  91. children: item.children.filter(({ name }) => name.includes(value))
  92. }
  93. ));
  94. let usedStorage = JSON.parse(window.localStorage.getItem('shrCommonlyUsed')) || [];
  95. this.shrCommonlyUsed = this.originData.filter(({ name, number }) => name.includes(value) && usedStorage.includes(number));
  96. },
  97. onItemClick(item) {
  98. // 分为常用 和其他分类
  99. /**
  100. * 如果是常用,把当前app移到常用的第一个,常用列表不增删
  101. * 如果是非常用,需要删掉常用的最后一个,然后把当前点击的app加入到常用的第一个,需要把常用的数据保存到 localStorage
  102. */
  103. let usedStorage = JSON.parse(window.localStorage.getItem('shrCommonlyUsed')) || []
  104. const number = item.number
  105. const index = usedStorage.indexOf(number)
  106. if (index === -1) {
  107. //ES6及以上语法修改,旧版本浏览器和手机不识别,报错
  108. // usedStorage = [number, ...usedStorage.slice(0, 7)]
  109. usedStorage = usedStorage.slice(0, 7);
  110. usedStorage.unshift(number);
  111. //this.shrCommonlyUsed = [item, ...this.shrCommonlyUsed.slice(0, 7)]
  112. this.shrCommonlyUsed = this.shrCommonlyUsed.slice(0, 7);
  113. this.shrCommonlyUsed.unshift(item);
  114. }else{
  115. if(index !== 0) {
  116. [usedStorage[0], usedStorage[index]] = [usedStorage[index], usedStorage[0]]
  117. this.shrCommonlyUsed = usedStorage.map((number)=>{
  118. return this.shrCommonlyUsed.find((data)=> data.number === number)
  119. })
  120. }
  121. }
  122. window.localStorage.setItem("shrCommonlyUsed", JSON.stringify(usedStorage))
  123. var params = new URLSearchParams(location.search);
  124. var searchParams = mbos.getRequestParams()
  125. // 处理天天勤跳转问题
  126. if(item.number === 'ttqin'){
  127. var urlArr = item.url.split('?')
  128. window.location.href = urlArr[0].startsWith("/mbos/")? urlArr[0] + '?' + "eid=" + searchParams.eid + "&appid=10036" + "&ticket=" + params.get("ticket") + "&mtimestamp=" + new Date().getTime() + "&" + urlArr[1] : item.url;
  129. }else{
  130. window.location.href = item.url.startsWith("/mbos/") ? item.url + "&eid=" + searchParams.eid + "&appid=10036" + "&ticket=" + params.get("ticket") + "&mtimestamp=" + new Date().getTime() : item.url;
  131. }
  132. },
  133. initsHRVersion(){
  134. var _this = this
  135. var param = [];
  136. mbos.eas.invokeScript({
  137. name: "getSHRVersionInfo",
  138. param: param,
  139. success: function (resp) {
  140. if(!resp.isMuiltLang){
  141. _this.showChangeLan = false
  142. }
  143. var version = resp.version.split(".").map(num => num - 0) // 8.8.0.1
  144. if(version[0] < 8 ){
  145. _this.versionError = true
  146. }
  147. if(version[0] === 8 && version[1] < 8 ){
  148. _this.versionError = true
  149. }
  150. if(version[3] > 0 || version[0] > 8) {
  151. _this.isAllowVersion = true;
  152. }
  153. },
  154. error: function (res) {
  155. _this.versionError = true
  156. },
  157. });
  158. },
  159. switchLanguage() {
  160. var paramObj = mbos.getRequestParams();
  161. var url = location.origin + location.pathname + '?';
  162. var paramIndex = 0;
  163. window.localStorage.setItem("ismoren", 1);
  164. //window.localStorage.removeItem("lang");
  165. var l = easContext.locale;
  166. if (l == "l2") {
  167. l = "zh_CN";
  168. localStorage.setItem('lang',l);
  169. } else if (l == "l1") {
  170. l = "en_US";
  171. localStorage.setItem('lang',l);
  172. } else if (l == "l3") {
  173. l = "zh_TW";
  174. localStorage.setItem('lang',l);
  175. }
  176. for (var key in paramObj) {
  177. var val = paramObj[key];
  178. if (key === 'canChangeLanguage') {
  179. continue;
  180. } else if (key === 'locale') {
  181. continue;
  182. } else if (key === 'mtimestamp') {
  183. continue;
  184. }
  185. url += paramIndex++ > 0 ? '&' + key + '=' + val : key + '=' + val;
  186. }
  187. location.href = url + '&canChangeLanguage=0&locale=' + l + '&mtimestamp=' + new Date().getTime();
  188. },
  189. //点击跳转隐私声明界面
  190. turnToPrivacy() {
  191. path = mbos.pageInfo.path;
  192. name = 'agreePrivacy.navui'
  193. mbos.ui.open({
  194. path: path,
  195. name: name
  196. });
  197. },
  198. disAgree(){
  199. var isYunZhiJia = window.navigator.userAgent.match(/Qing\/.*;(iOS|iPhone|Android).*/) ? true : false;
  200. var isYzjDesktop = window.navigator.userAgent.match(/.*Qing\/.*/) ? true : false;
  201. if(isYunZhiJia || isYzjDesktop){
  202. XuntongJSBridge.call('closeWebView');
  203. }else{
  204. window.close();
  205. }
  206. },
  207. Agreement(){
  208. $('.mask-wrapper').hide();
  209. let that = this;
  210. let arr =[];
  211. that.agreements.filter(item=>{
  212. arr.push(item.id);
  213. });
  214. let obj = {
  215. signPerson: easContext.userID,
  216. agreementIds: arr.join(','),
  217. signState: 0
  218. };
  219. const param = ['signAgreementService', JSON.stringify(obj)];
  220. mbos.eas.invokeScript({
  221. name: 'commonOSFservice',
  222. needShowLoading: true,
  223. param: param,
  224. success: function(res){
  225. console.log(res,'sign');
  226. },
  227. error: function(res){
  228. console.log(res)
  229. }
  230. })
  231. },
  232. //获取未签署声明协议
  233. getAgreementInfo(){
  234. let that = this;
  235. let obj = {
  236. target: 'HomePage',//传应用场景的number
  237. lang: easContext.locale, //当前语言
  238. person: easContext.userID //当前签署人
  239. };
  240. const param = ['getAgreementInfoService', JSON.stringify(obj)];
  241. setTimeout(() =>{
  242. mbos.eas.invokeScript({
  243. name: 'commonOSFservice',
  244. param: param,
  245. success: function(res){
  246. if(res.errorCode == 0){
  247. if(that.isAllowVersion) {
  248. that.signAgreement = true;
  249. $('.mask-wrapper').show();
  250. }
  251. that.agreements = res.data;
  252. }else{
  253. if(res.data.length == 0) {
  254. that.signAgreement = false;
  255. }
  256. }
  257. },
  258. error: function(res){
  259. console.log(res,'error')
  260. }
  261. })
  262. },100)
  263. },
  264. //查看协议内容
  265. getAgreement(id){
  266. let that = this;
  267. let obj= {
  268. id: id,
  269. lang: easContext.locale
  270. };
  271. const param = ['getAgreementServiceByID', JSON.stringify(obj)];
  272. mbos.eas.invokeScript({
  273. name: 'commonOSFservice',
  274. needShowLoading: true,
  275. param: param,
  276. success: function(res){
  277. if(res.errorCode == '0'){
  278. that.showText = true;
  279. that.agreementText = res.data.content;
  280. }
  281. },
  282. error: function(res){
  283. console.log(res)
  284. }
  285. })
  286. },
  287. closeBtn(){
  288. this.showText = false;
  289. }
  290. }
  291. })