# 通用方法
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/01.%20%E5%9F%BA%E7%A1%80%E8%A7%84%E8%8C%83/18.%20%E5%89%8D%E7%AB%AF%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/%E9%80%9A%E7%94%A8%E6%96%B9%E6%B3%95


# 常用写法

## TXS 写法

```ts
export function createSimpleTransition(name: string, origin = 'top center 0', mode?: Mode) {
  return defineComponent({
    name,
    props: {
      group: {
        type: Boolean as PropType<boolean>,
        default: false,
      },
      mode: {
        type: String as PropType<Mode>,
        default: mode,
      },
      origin: {
        type: String as PropType<string>,
        default: origin,
      },
    },
    setup(props, { slots, attrs }) {
      const onBeforeEnter = (el: HTMLElement) => {
        el.style.transformOrigin = props.origin;
      };

      return () => {
        const Tag = !props.group ? Transition : TransitionGroup;
        return (
          <Tag name={name} mode={props.mode} {...attrs} onBeforeEnter={onBeforeEnter}>
            {() => getSlot(slots)}
          </Tag>
        );
      };
    },
  });
}
```

## 查询字典

``` ts
import { initDictOptions } from '/@/utils/dict';

const dictOptions = ref<any>([]);
async function initDictConfig() {
  dictOptions.value['target'] = await initDictOptions('offi_msg_target');
}
```

## 缓存的设置与读取

``` ts
import { MINI_ALIAS } from '/@/enums/cacheEnum';
import { createLocalStorage } from '/@/utils/cache';
const ls = createLocalStorage();
ls.set(MINI_ALIAS, '值');
ls.get(MINI_ALIAS);
```

## 小程序与公众号是否授权, 未授权跳转授权页

``` ts
 import { useMiniAppid, useOffiAppid } from '/@/hooks/auth/useAppid';
* 小程序
 useMiniAppid()
* 公众号
 useOffiAppid()
```

## 字典加 where

``` ts
  <j-search-select
    v-model:value="model.templateId"
    dict="cdp.mess_send_template where plat_code = 'wxgzh',title,id"
    placeholder="请选择模板"
    :disabled="disabledShow"
    @change="handleSelectTemplate"
  />
```

## 唯一值校验

``` ts
import { duplicateValidate } from '/@/utils/helper/validator';

const validatorRules = {
  code: [{ required: false }, { validator: codeDuplicatevalidate }],
};

async function codeDuplicatevalidate(_r, value) {
  return duplicateValidate('cdp.mess_task', 'code', value, formData.id || '');
}
```

## 弹框选择 api 选择字典

``` jsx
import { SelectorApi } from '/@/components/SelectorApi';

<SelectorApi
  api="/cdptag/cdpTag/list"
  rowKey="id"
  :searchList="searchList"
  :columns="personnelColumns"
  v-model:value="value"
  placeholder="请选择标签" >
</SelectorApi>


 const value = ref<string>('')
 const searchList = ref<any>([
   {
     type: 'input',
     label: '标签名称',
     value: 'name',
     dictCode: '',
   },
 ])
const personnelColumns = ref<any>([
  {
    title: '员工ID',
    dataIndex: 'userId',
    align: 'center',
  },
])

```

| 参数          | 说明                                  | 类型    | 默认值 |
| ------------- | ------------------------------------- | ------- | ------ |
| api           | 接口地址 post                         | string  |
| rowKey        | 表格选中的键名 (也是返回的字段)        | string  |
| rowName       | input 中显示的内容 (一般做翻译使用)    | string  |
| columns       | 表格的表头与 ant 保持一致             | any[]   |
| searchList    | 搜索框渲染 (searchListConfig)          | Array   |
| v-model:value | 根据 rowKey 的字段返回,多个以逗号分割 | string  |
| placeholder   | input 提示内容                        | string  |
| title         | 弹框标题                              | string  |
| disabled      | input 禁用                            | boolean |
| width         | 弹窗宽度                              | string  |
 | btnName | 按钮名称 | string | 选择 |
| isMultiple    | 是否支持选中多个                      | boolean | true   |

searchListConfig

| 参数     | 说明          | 类型   | 默认值 |
| -------- | ------------- | ------ | ------ |
| type     | 组件类型      | string |
| label    | FormItem 名字 | string |
| value    | 搜索的字段    | string |
| dictCode | 字典 code     | string |
