闫增涛
2024-02-23 fdfb3ca757ecd6c396632ed276ff354671d3a7e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function getInstance(context, selector = '#wr-reason-sheet') {
  if (!context) {
    const pages = getCurrentPages();
    const page = pages[pages.length - 1];
    context = page;
  }
  const instance = context && context.selectComponent(selector);
  if (!instance) {
    console.warn(`未找到reason-sheet组件,请检查selector是否正确`);
    return null;
  }
  return instance;
}
 
export default function (options) {
  const { context, selector, ..._options } = options;
  return new Promise((resolve, reject) => {
    const instance = getInstance(context, selector);
    if (instance) {
      instance.setData(Object.assign({}, _options));
      instance._onCancel = () => reject();
      instance._onConfirm = (indexes) => resolve(indexes);
    }
  });
}