app-jump-button.vue 16 KB

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