app-jump-button.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <form v-if="form" report-submit @submit="jumpLogic">
  3. <!-- #ifndef MP-ALIPAY -->
  4. <button
  5. :open-type="open_type === 'contact' ? 'contact': open_type === 'share' ? 'share' : ''"
  6. hover-class="none"
  7. :style="{'background-color': `${backgroundColor ? backgroundColor : '' }`, 'height': `${height}%`, 'width': `${width}%`}"
  8. :class="[`${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : arrangement === 'left' ? 'app-button-left': arrangement === 'topCenter' ? 'app-button-top-cross-center' : arrangement === 'a' ? 'app-left' : arrangement === 'b' ? 'app-left-between' : ''}`]"
  9. formType="submit"
  10. >
  11. <slot></slot>
  12. </button>
  13. <!-- #endif -->
  14. <!-- #ifdef MP-ALIPAY -->
  15. <template v-if="open_type === 'contact'">
  16. <view style="width: 100%;height: 100%;padding: 24rpx 0;" class="dir-top-nowrap cross-center main-between">
  17. <contact-button tnt-inst-id="" scene=""/>
  18. <view style="font-size: 24rpx; color: #666666;">
  19. 客服
  20. </view>
  21. </view>
  22. </template>
  23. <template v-if="open_type !== 'contact'">
  24. <button
  25. :open-type="open_type === 'share' ? 'share' : ''" hover-class="none"
  26. :style="{'background-color': `${backgroundColor ? backgroundColor : '' }`, 'height': `${height}%`, 'width': `${width}%`}"
  27. :class="[`${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : arrangement === 'left' ? 'app-button-left': arrangement === 'topCenter' ? 'app-button-top-cross-center' : arrangement === 'a' ? 'app-left' : arrangement === 'b' ? 'app-left-between' : ''}`]"
  28. formType="submit"
  29. >
  30. <slot></slot>
  31. </button>
  32. </template>
  33. <!-- #endif -->
  34. </form>
  35. <button
  36. v-else
  37. :open-type="open_type === 'contact' ? 'contact': ''" hover-class="none"
  38. :style="{'background-color': `${backgroundColor ? backgroundColor : '' }`, 'height': `${height}%`, 'width': `${width}%`}"
  39. :class="[`${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : arrangement === 'left' ? 'app-button-left': arrangement === 'topCenter' ? 'app-button-top-cross-center' : arrangement === 'a' ? 'app-left' : arrangement === 'b' ? 'app-left-between' : ''}`]"
  40. @click="jumpLogic"
  41. >
  42. <slot></slot>
  43. </button>
  44. </template>
  45. <script>
  46. import {push} from '../../../core/formId.js';
  47. import {clearStorage} from '../../../core/cache.js';
  48. export default {
  49. name: 'app-jump-button',
  50. props: {
  51. item: Object,
  52. arrangement: {
  53. type: String,
  54. default: function () {
  55. return 'row';
  56. }
  57. },
  58. backgroundColor: String,
  59. form: {
  60. type: Boolean,
  61. default: function () {
  62. return true;
  63. }
  64. },
  65. height: {
  66. type: String,
  67. default: function () {
  68. return '100';
  69. }
  70. },
  71. width: {
  72. type: String,
  73. default: function () {
  74. return '100';
  75. }
  76. },
  77. open_type: {
  78. type: String,
  79. default: function () {
  80. return 'navigate';
  81. }
  82. },
  83. url: {
  84. type: String,
  85. default: function () {
  86. return '';
  87. }
  88. },
  89. params: {
  90. type: Array,
  91. default: function () {
  92. return [];
  93. }
  94. },
  95. number: {
  96. type: String,
  97. default: function () {
  98. return '';
  99. }
  100. },
  101. appId: {
  102. type: String,
  103. default: function () {
  104. return '';
  105. }
  106. },
  107. path: {
  108. type: String,
  109. default: function () {
  110. return '';
  111. }
  112. },
  113. latitude: {
  114. type: String,
  115. default: function () {
  116. return '0';
  117. }
  118. },
  119. longitude: {
  120. type: String,
  121. default: function () {
  122. return '0';
  123. }
  124. },
  125. address: {
  126. type: String,
  127. default: function () {
  128. return '';
  129. }
  130. }
  131. },
  132. methods: {
  133. jumpLogic(e) {
  134. if (this.form) push(e.detail.formId);
  135. switch (this.open_type) {
  136. case 'reLaunch':
  137. uni.reLaunch({
  138. url: this.url,
  139. });
  140. break;
  141. case 'redirect':
  142. uni.redirectTo({
  143. url: this.url
  144. });
  145. break;
  146. case 'navigate':
  147. if (this.url) {
  148. let url = this.url;
  149. if (this.params.length > 0) {
  150. let p = `?`;
  151. for (let i = 0; i < this.params.length; i++) {
  152. p += `${this.params[i].key}=${this.params[i].value}&`
  153. }
  154. url += p.slice(0, p.length - 1);
  155. }
  156. /* #ifdef MP-BAIDU || MP-TOUTIAO */
  157. if (this.url !== '/plugins/step/index/index') {
  158. uni.navigateTo({
  159. url: url
  160. });
  161. }
  162. /* #endif */
  163. /* #ifdef MP-WEIXIN || MP-ALIPAY */
  164. uni.navigateTo({
  165. url: url
  166. });
  167. /* #endif */
  168. }
  169. break;
  170. case 'app_admin':
  171. if (this.$store.state.user.info.identity.is_admin == 1) {
  172. uni.navigateTo({
  173. url: this.url,
  174. });
  175. }
  176. break;
  177. case 'back':
  178. uni.navigateBack({});
  179. break;
  180. case 'tel':
  181. if (this.params.length === 1) {
  182. uni.makePhoneCall({
  183. phoneNumber: this.params[0].value
  184. });
  185. } else if (this.number) {
  186. uni.makePhoneCall({
  187. phoneNumber: this.number
  188. });
  189. } else {
  190. uni.makePhoneCall({
  191. phoneNumber: this.url.split('?')[1].split('=')[1],
  192. });
  193. }
  194. break;
  195. case 'web':
  196. if (this.params.length > 0) {
  197. uni.navigateTo({
  198. url: `${this.url}?url=${encodeURIComponent(this.params[0].value)}`
  199. });
  200. } else {
  201. uni.navigateTo({
  202. url: this.url
  203. });
  204. }
  205. break;
  206. case 'app':
  207. if (this.url) {
  208. let originalPath = '';
  209. if (this.url !== 'app') {
  210. originalPath = this.url.split('app?')[1];
  211. } else {
  212. for (let i = 0; i < this.params.length; i++) {
  213. originalPath += `${this.params[i].key}=${this.params[i].value}&`;
  214. }
  215. }
  216. if (typeof originalPath !== 'string') return;
  217. let groups = originalPath.split('&');
  218. let obj = {};
  219. for (let i in groups) {
  220. if (typeof groups[i] !== 'string') continue;
  221. if (!groups[i].length) continue;
  222. let kvs = groups[i].split('=');
  223. if (kvs.length !== 2) {
  224. let s = '';
  225. for (let i = 1; i < kvs.length; i++) {
  226. if (i+1 === kvs.length) {
  227. continue;
  228. } else {
  229. s += `${kvs[i]}=${kvs[i+1]}`
  230. }
  231. }
  232. obj[kvs[0]] = s;
  233. } else {
  234. obj[kvs[0]] = kvs[1];
  235. }
  236. }
  237. let params = obj;
  238. console.log(params);
  239. let appId = '';
  240. let path = '';
  241. // #ifdef MP-WEIXIN
  242. appId = params.app_id || '';
  243. path = params.path || '';
  244. // #endif
  245. // #ifdef MP-ALIPAY
  246. appId = params.ali_app_id || '';
  247. path = params.ali_path || '';
  248. // #endif
  249. // #ifdef MP-TOUTIAO
  250. appId = params.tt_app_id || '';
  251. path = params.tt_path || '';
  252. // #endif
  253. // #ifdef MP-BAIDU
  254. appId = params.bd_app_key || '';
  255. path = params.bd_path || '';
  256. // #endif
  257. console.log(path);
  258. uni.navigateToMiniProgram({
  259. appId: appId,
  260. path: path,
  261. success(e) {
  262. console.log('打开小程序成功', e);
  263. },
  264. fail(e) {
  265. console.log('打开小程序失败', e);
  266. }
  267. });
  268. } else if (this.appId) {
  269. uni.navigateToMiniProgram({
  270. appId: this.appId,
  271. path: this.path ? this.path : '',
  272. success(res) {
  273. },
  274. fail(res) {
  275. }
  276. });
  277. }
  278. break;
  279. case 'clear_cache':
  280. uni.showModal({
  281. title: '清理缓存',
  282. content: '确定要清理缓存?',
  283. cancelText: '取消',
  284. confirmText: '确认',
  285. success: (e) => {
  286. if (e.confirm) {
  287. // uni.showLoading({
  288. // title: '清理缓存...',
  289. // });
  290. clearStorage();
  291. if (this.$user && this.$store && this.$store.state.user.accessToken) {
  292. this.$user.loginByToken(this.$store.state.user.accessToken);
  293. }
  294. this.$store.dispatch('mallConfig/actionResetConfig');
  295. // uni.hideLoading();
  296. uni.showToast({
  297. title: '清理完成',
  298. duration: 1000,
  299. icon: 'none',
  300. });
  301. }
  302. },
  303. });
  304. break;
  305. case 'map':
  306. uni.openLocation({
  307. latitude: Number(this.latitude),
  308. longitude: Number(this.longitude),
  309. name: this.address,
  310. address: this.address,
  311. success: function () {
  312. },
  313. fail: function (res) {
  314. }
  315. });
  316. break;
  317. case 'share':
  318. // uni.share({
  319. // provider: 'weixin',
  320. // type: 5,
  321. // imageUrl: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png',
  322. // title: '欢迎体验uniapp',
  323. // miniProgram: {
  324. // id: 'gh_abcdefg',
  325. // path: 'pages/index/index',
  326. // type: 0,
  327. // webUrl: 'http://uniapp.dcloud.io'
  328. // },
  329. // success: ret => {
  330. // }
  331. // });
  332. }
  333. }
  334. }
  335. }
  336. </script>
  337. <style scoped lang="scss">
  338. button {
  339. display: block;
  340. line-height: inherit;
  341. text-align: inherit;
  342. padding: 0 0;
  343. background: transparent;
  344. border: none;
  345. border-radius: 0;
  346. overflow: inherit;
  347. font-size: inherit;
  348. color: inherit;
  349. }
  350. button:after {
  351. display: none;
  352. }
  353. button.button-hover {
  354. color: inherit;
  355. background-color: transparent;
  356. }
  357. form {
  358. display: block;
  359. height: 100%;
  360. width: 100%;
  361. }
  362. .app-button-column {
  363. height: 100%;
  364. width: 100%;
  365. display: flex;
  366. flex-direction: column;
  367. justify-content: center;
  368. align-items: center;
  369. }
  370. .app-button-row {
  371. height: 100%;
  372. width: 100%;
  373. display: flex;
  374. flex-direction: row;
  375. justify-content: center;
  376. align-items: center;
  377. }
  378. .app-button-left {
  379. height: 100%;
  380. width: 100%;
  381. display: flex;
  382. flex-direction: row;
  383. justify-content: flex-start;
  384. }
  385. .app-button-top-cross-center {
  386. display: -webkit-box;
  387. display: -webkit-flex;
  388. display: flex;
  389. -webkit-box-orient: vertical;
  390. -webkit-flex-direction: column;
  391. flex-direction: column;
  392. flex-wrap: nowrap;
  393. -webkit-align-items: center;
  394. align-items: center;
  395. }
  396. .app-left {
  397. height: 100%;
  398. width: 100%;
  399. display: flex;
  400. flex-direction: column;
  401. justify-content: flex-start;
  402. }
  403. .app-left-between {
  404. display: -webkit-box;
  405. display: -webkit-flex;
  406. display: flex;
  407. -webkit-flex-direction: row;
  408. flex-direction: row;
  409. flex-wrap: nowrap;
  410. justify-content: space-between;
  411. align-items: center;
  412. }
  413. </style>