app-jump-button.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. import {clearStorage} from '../../../core/cache.js';
  40. export default {
  41. name: 'app-jump-button',
  42. props: {
  43. item: Object,
  44. arrangement: {
  45. type: String,
  46. default: function () {
  47. return 'row';
  48. }
  49. },
  50. backgroundColor: String,
  51. form: {
  52. type: Boolean,
  53. default: function () {
  54. return true;
  55. }
  56. },
  57. height: {
  58. type: String,
  59. default: function () {
  60. return '100';
  61. }
  62. },
  63. width: {
  64. type: String,
  65. default: function () {
  66. return '100';
  67. }
  68. },
  69. open_type: {
  70. type: String,
  71. default: function () {
  72. return 'navigate';
  73. }
  74. },
  75. url: {
  76. type: String,
  77. default: function () {
  78. return '';
  79. }
  80. },
  81. params: {
  82. type: Array,
  83. default: function () {
  84. return [];
  85. }
  86. },
  87. number: {
  88. type: String,
  89. default: function () {
  90. return '';
  91. }
  92. },
  93. appId: {
  94. type: String,
  95. default: function () {
  96. return '';
  97. }
  98. },
  99. path: {
  100. type: String,
  101. default: function () {
  102. return '';
  103. }
  104. },
  105. latitude: {
  106. type: String,
  107. default: function () {
  108. return '0';
  109. }
  110. },
  111. longitude: {
  112. type: String,
  113. default: function () {
  114. return '0';
  115. }
  116. },
  117. address: {
  118. type: String,
  119. default: function () {
  120. return '';
  121. }
  122. }
  123. },
  124. methods: {
  125. jumpLogic(e) {
  126. if (this.form) push(e.detail.formId);
  127. switch (this.open_type) {
  128. case 'reLaunch':
  129. uni.reLaunch({
  130. url: this.url,
  131. });
  132. break;
  133. case 'redirect':
  134. uni.redirectTo({
  135. url: this.url
  136. });
  137. break;
  138. case 'navigate':
  139. if (this.url) {
  140. let url = this.url;
  141. if (this.params.length > 0) {
  142. let p = `?`;
  143. for (let i = 0; i < this.params.length; i++) {
  144. p += `${this.params[i].key}=${this.params[i].value}&`
  145. }
  146. url = url.split('?')[0];
  147. url += p.slice(0, p.length - 1);
  148. }
  149. /* #ifdef MP-BAIDU */
  150. if (this.url !== '/plugins/step/index/index') {
  151. uni.navigateTo({
  152. url: url
  153. });
  154. }
  155. /* #endif */
  156. /* #ifdef MP-TOUTIAO */
  157. if (this.url !== '/plugins/step/index/index' && this.url.indexOf('/plugins/community') === -1) {
  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. let appId = '';
  239. let path = '';
  240. // #ifdef MP-WEIXIN
  241. appId = params.app_id || '';
  242. path = params.path || '';
  243. // #endif
  244. // #ifdef MP-ALIPAY
  245. appId = params.ali_app_id || '';
  246. path = params.ali_path || '';
  247. // #endif
  248. // #ifdef MP-TOUTIAO
  249. appId = params.tt_app_id || '';
  250. path = params.tt_path || '';
  251. // #endif
  252. // #ifdef MP-BAIDU
  253. appId = params.bd_app_key || '';
  254. path = params.bd_path || '';
  255. // #endif
  256. uni.navigateToMiniProgram({
  257. appId: appId,
  258. path: path
  259. });
  260. } else if (this.appId) {
  261. uni.navigateToMiniProgram({
  262. appId: this.appId,
  263. path: this.path ? this.path : ''
  264. });
  265. }
  266. break;
  267. case 'clear_cache':
  268. uni.showModal({
  269. content: '确定要清理缓存?',
  270. cancelText: '取消',
  271. confirmText: '确认',
  272. success: (e) => {
  273. if (e.confirm) {
  274. // uni.showLoading({
  275. // title: '清理缓存...',
  276. // });
  277. clearStorage();
  278. if (this.$user && this.$store && this.$store.state.user.accessToken) {
  279. this.$user.loginByToken(this.$store.state.user.accessToken);
  280. }
  281. this.$store.dispatch('mallConfig/actionResetConfig');
  282. // uni.hideLoading();
  283. uni.showToast({
  284. title: '清理完成',
  285. duration: 1000,
  286. icon: 'none',
  287. });
  288. }
  289. },
  290. });
  291. break;
  292. case 'map':
  293. uni.openLocation({
  294. latitude: Number(this.latitude),
  295. longitude: Number(this.longitude),
  296. name: this.address,
  297. address: this.address
  298. });
  299. break;
  300. case 'share':
  301. // uni.share({
  302. // provider: 'weixin',
  303. // type: 5,
  304. // imageUrl: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png',
  305. // title: '欢迎体验uniapp',
  306. // miniProgram: {
  307. // id: 'gh_abcdefg',
  308. // path: 'pages/index/index',
  309. // type: 0,
  310. // webUrl: 'http://uniapp.dcloud.io'
  311. // },
  312. // success: ret => {
  313. // }
  314. // });
  315. }
  316. }
  317. }
  318. }
  319. </script>
  320. <style scoped lang="scss">
  321. button {
  322. display: block;
  323. line-height: inherit;
  324. text-align: inherit;
  325. padding: 0 0;
  326. background: transparent;
  327. border: none;
  328. border-radius: 0;
  329. overflow: inherit;
  330. font-size: inherit;
  331. color: inherit;
  332. }
  333. button:after {
  334. display: none;
  335. }
  336. button.button-hover {
  337. color: inherit;
  338. background-color: transparent;
  339. }
  340. form {
  341. display: block;
  342. height: 100%;
  343. width: 100%;
  344. }
  345. .app-button-column {
  346. height: 100%;
  347. width: 100%;
  348. display: flex;
  349. flex-direction: column;
  350. justify-content: center;
  351. align-items: center;
  352. }
  353. .app-button-row {
  354. height: 100%;
  355. width: 100%;
  356. display: flex;
  357. flex-direction: row;
  358. justify-content: center;
  359. align-items: center;
  360. }
  361. .app-button-left {
  362. height: 100%;
  363. width: 100%;
  364. display: flex;
  365. flex-direction: row;
  366. justify-content: flex-start;
  367. }
  368. .app-button-top-cross-center {
  369. display: -webkit-box;
  370. display: -webkit-flex;
  371. display: flex;
  372. -webkit-box-orient: vertical;
  373. -webkit-flex-direction: column;
  374. flex-direction: column;
  375. flex-wrap: nowrap;
  376. -webkit-align-items: center;
  377. align-items: center;
  378. }
  379. .app-left {
  380. height: 100%;
  381. width: 100%;
  382. display: flex;
  383. flex-direction: column;
  384. justify-content: flex-start;
  385. }
  386. .app-left-between {
  387. display: -webkit-box;
  388. display: -webkit-flex;
  389. display: flex;
  390. -webkit-flex-direction: row;
  391. flex-direction: row;
  392. flex-wrap: nowrap;
  393. justify-content: space-between;
  394. align-items: center;
  395. }
  396. </style>