1 | import { setNavigationBarLoading, setTitle, setNavigationBarStyle } from '@tarojs/router';
|
2 | import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../../../utils/index.js';
|
3 | import { MethodHandler } from '../../../utils/handler.js';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function showNavigationBarLoading(options = {}) {
|
10 | const { success, fail, complete } = options;
|
11 | const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete });
|
12 | setNavigationBarLoading(true);
|
13 | return handle.success();
|
14 | }
|
15 | function setNavigationBarTitle(options) {
|
16 |
|
17 | const isObject = shouldBeObject(options);
|
18 | if (!isObject.flag) {
|
19 | const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
|
20 | console.error(res.errMsg);
|
21 | return Promise.reject(res);
|
22 | }
|
23 | const { title, success, fail, complete } = options;
|
24 | const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
|
25 | if (!title || typeof title !== 'string') {
|
26 | return handle.fail({
|
27 | errMsg: getParameterError({
|
28 | para: 'title',
|
29 | correct: 'String',
|
30 | wrong: title
|
31 | })
|
32 | });
|
33 | }
|
34 | setTitle(title);
|
35 | return handle.success();
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 | const setNavigationBarColor = (options) => {
|
41 | const { backgroundColor, frontColor, success, fail, complete } = options;
|
42 | const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
|
43 | const meta = document.createElement('meta');
|
44 | meta.setAttribute('name', 'theme-color');
|
45 | meta.setAttribute('content', backgroundColor);
|
46 | document.head.appendChild(meta);
|
47 | setNavigationBarStyle({ frontColor, backgroundColor });
|
48 | return handle.success();
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 | function hideNavigationBarLoading(options = {}) {
|
54 | const { success, fail, complete } = options;
|
55 | const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete });
|
56 | setNavigationBarLoading(false);
|
57 | return handle.success();
|
58 | }
|
59 | const hideHomeButton = temporarilyNotSupport('hideHomeButton');
|
60 |
|
61 | export { hideHomeButton, hideNavigationBarLoading, setNavigationBarColor, setNavigationBarTitle, showNavigationBarLoading };
|
62 |
|