diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 10bfa0f..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -/src/sdk/libs diff --git a/.eslintrc.js b/.eslintrc.js index 3b53d10..115cc02 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,241 +1,31 @@ - -// "off" or 0 - turn the rule off -// "warn" or 1 - turn the rule on as a warning (doesn't affect exit code) -// "error" or 2 - turn the rule on as an error (exit code will be 1) - +/* + * Eslint config file + * Documentation: https://eslint.org/docs/user-guide/configuring/ + * Install the Eslint extension before using this feature. + */ module.exports = { - root: true, - parserOptions: { - ecmaVersion: 6, // es6 - sourceType: "module", // script | module - ecmaFeatures: { - jsx: true, - globalReturn: false, // top 作用域 return - impliedStrict: false, // 执行 strict 标准 - experimentalObjectRestSpread: true, // 实验中的语法特性,react 需要 - allowImportExportEverywhere: false, // babel-eslint 提供 - codeFrame: false // babel-eslint 提供 - } - }, - parser: "babel-eslint", // babel-eslint | esprima | espree (default) - env: { - browser: true, - es6: true, - amd: true, - jest: true, - jquery: true, - commonjs: true, - // shared-node-browser: false, // 不能开启? - - worker: false, - node: false, - serviceworker: false, - mocha: false, - jasmine: false, - phantomjs: false, - protractor: false, - qunit: false, - prototypejs: false, - shelljs: false, - meteor: false, - mongo: false, - applescript: false, - nashorn: false, - atomtest: false, - embertest: false, - webextensions: false, - greasemonkey: false, - }, - // 假定的全局变量,避免模块内 no-undef 时报假错 - // 值为 false 时,能检测全局被覆盖 - globals: { - wx: true, - App: true, - Page: true, - Component: true, - getApp: true, - getCurrentPages: true, - }, - - rules: { - - /* - --------------- - POSSIBLE ERRORS - --------------- - */ - "no-extra-semi": 1, // 禁止多余的分号 - - "for-direction": 2, // for 循环死了 - "no-cond-assign": 2, // 防止 if 写成赋值 - "no-debugger": 2, // 禁止 debugger - "no-dupe-args": 2, // 禁止参数重名 - "no-dupe-keys": 2, // 禁止 key 重名 - "no-duplicate-case": 2, // 禁止 case 重复 - "no-func-assign": 2, // 禁止覆盖函数字面量 - "no-inner-declarations": [2, "both"], // 禁止在 if 中 var - "no-irregular-whitespace": 2, // 禁止非常规空白 - "no-prototype-builtins": 2, // 禁止直接调用 obj 上的 proto 方法 - "no-sparse-arrays": 2, // 防止数组中多余的逗号 - "no-template-curly-in-string": 2, // 禁止字符串中出现 ${} - "no-unreachable": 2, // 禁止出现无法执行到的语句 - "no-unsafe-finally": 2, // 禁止 finally 出现控制语句 - "no-unsafe-negation": 2, // 禁止有歧义、不安全的 ! 号 - "use-isnan": 2, // 强制 isNaN() - "valid-typeof": 2, // 防止 typeof 类型的字符写错 - "valid-jsdoc": 2, // 如果有的话,校验 jsdoc - - - /* - -------------- - BEST PRACTICES - -------------- - */ - // "curly": 2, // 控制语句块强制大括号(冲突 nonblock-statement-body-position) - // "no-case-declarations": 2, // 强制 case 加大括号,明确 let 等的作用域(非 es6 无意义) - "accessor-pairs": 2, // 如果 setter,则不能没有 getter - "block-scoped-var": 2, // 禁止块级作用域中 var 和使用该 var - "default-case": 2, // switch 强制 default - "no-alert": 2, // 禁止 alert prompt confirm 等 - "no-caller": 2, // 禁止 arguments.caller - "no-eval": 2, // 禁止 eval - "no-extra-bind": 2, // 禁止无意义的 bind() 调用 - "no-fallthrough": 2, // 禁止 case fallthrough - "no-floating-decimal": 2, // 禁止省略形式的浮点定义 - "no-global-assign": 2, // 禁止覆盖全局对象 - "no-implied-eval": 2, // 禁止隐式的 eval,比如 setTimeout - "no-iterator": 2, // 禁止替换原生的 __iterator__ - "no-proto": 2, // 禁止使用 __proto__ - "no-labels": 2, // 禁止使用 label 语句 - "no-lone-blocks": 2, // 禁止无意义的 block 标记 - "no-new-func": 2, // 禁止使用 Function - "no-new-wrappers": 2, // 禁止使用带 new 的基本类型封装 - "no-redeclare": 2, // 禁止重复声明 - "no-return-assign": 2, // 禁止不打括号的 return 赋值 - "no-sequences": 2, // 禁止使用逗号运算符 - "no-throw-literal": 2, // 禁止 throw 文本 - "no-useless-concat": 2, // 禁止无意义的拼接 - "no-useless-escape": 2, // 禁止无意义的转义 - "no-void": 2, // 禁止使用 void - "no-with": 2, // 禁止使用 with - "yoda": [2, "never"], // 禁止反向的判断比较 - - "no-return-await": 2, // 禁止没有意义的 return 时使用 await - "require-await": 2, // 禁止 async 的 func 中没有 await - - "dot-notation": [1, { "allowKeywords":false }], // 警告:不必要的计算属性访问 or 直接访问关键字为 key 的属性 - "no-eq-null": 1, // null 必须 === - "vars-on-top": 1, // 建议变量都定义在 scope 顶部 - "radix": 1, // 建议 parseInt 带上进制参数 - "no-invalid-this": 1, // 限制 this 的使用 - "consistent-return": 1, // 建议统一 return - "no-else-return": 1, // 建议统一 return - "no-useless-return": 1, // 建议删除、合并没有意义的 return - // "guard-for-in": 1, // for in 的警告(观察观察) - - // 如果 method 没有使用 this,应该使用 static - "class-methods-use-this": [1, { "exceptMethods":["render"] }], - // 强制 promise reject error 对象 - "prefer-promise-reject-errors": [2, { "allowEmptyReject":true }], - // 强制 IIFE 必须打括号 - "wrap-iife": [2, "any", { "functionPrototypeMethods":true }], - // 禁止魔法数字 - "no-magic-numbers": [1, { "detectObjects":true, "ignoreArrayIndexes":true, "ignore":[0,1,-1] }], - - - - /* - --------- - VARIABLES - --------- - */ - "strict": 2, // 禁止 strict 指令 - "no-delete-var": 2, // 禁止 delete 变量(好像语法上就不允许了) - "no-shadow-restricted-names": 2, // 禁止定义与全局重名的变量 - "no-undef": 2, // 禁止使用未定义变量 - "no-undef-init": 2, // 禁止显式定义为 undefined - "no-unused-vars": 1, // 警告未使用的变量 - "no-use-before-define": [1, "nofunc"], // 警告提前使用了变量 - "no-restricted-globals": [2, "name", "stop"], // 禁止使用的全局变量 - - - /* - ---------------- - STYLISTIC ISSUES - ---------------- - */ - "comma-spacing": 1, // 警告:逗号无空格间隔 - "computed-property-spacing": 1, // 警告:计算属性左右加空格 - "consistent-this": [1, "me"], // 警告:不规范的 this 别名 - "eol-last": 1, // 警告:文件末无空行 - "func-call-spacing": 1, // 警告:不规范的调用前空格 - "new-parens": 1, // 警告:new 调用必须打括号 - "no-lonely-if": 1, // 警告:else 中的只有 if 不合理 - "no-mixed-operators": 1, // 警告:表达式中运算符过于复杂 - "no-mixed-spaces-and-tabs": 1, // 警告:混合了 tab 和 space - "no-unneeded-ternary": 1, // 警告:精简条件表达式 - "object-curly-spacing": [1, "always"], // 警告:obj 大括号需要空格 - "semi": 1, // 警告:缺少分号 - "semi-spacing": 1, // 警告:分号后需要空格 - "switch-colon-spacing": 1, // 警告:case 冒号需要空格 - "spaced-comment": 1, // 警告:注释需要空格 - "space-unary-ops": 1, // 警告:一元符空格问题 - "space-infix-ops": 1, // 警告:运算符必须空格 - "key-spacing": [1, { "mode": "minimum" }], // 警告:obj 的 key 冒号需要空格 - - "jsx-quotes": 1, // 警告:jsx 最好用双引 - - "no-whitespace-before-property": 2, // 禁止 dot 属性访问带空格 - "nonblock-statement-body-position": 2, // 强制单句控制写成一行 - - // 警告:链式调用必须断行,3 级以上 - "newline-per-chained-call": [1, { "ignoreChainWithDepth": 3 }], - // 函数小括号的空格定义 - "space-before-function-paren": [1, { - "anonymous": "never", - "named": "never", - "asyncArrow": "always" - }], - // 引号规则 - "quotes": [1, "double", { "allowTemplateLiterals":true }], - // 强制属性引号 - "quote-props": [2, "as-needed", { "keywords":true }], - // 警告:行末空格 - "no-trailing-spaces": [1, { "skipBlankLines":true }], - // 警告:缩进 tab - "indent": [1, "tab", { "MemberExpression":0 }], - // 关键字左右空格 - "keyword-spacing": [1, { - "overrides": { - "if": { before:false, after:false }, - "else": { before:false, after:false }, - "do": { before:false, after:false }, - "while": { before:false, after:false }, - "for": { before:false, after:false }, - - "try": { before:false, after:false }, - "catch": { before:false, after:false }, - "finally": { before:false, after:false }, - - "switch": { before:false, after:false }, - "default": { before:false, after:false }, - } - }], - // 警告:大写调用就是 new - "new-cap": [1, { - "newIsCapExceptions":[], - "capIsNewExceptions":["Deferred"] - }], - // 大括号外面的空格 - "space-before-blocks": [1, { - "functions": "never", - "keywords": "never", - "classes": "always" - }], - // 大括号样式 - "brace-style": [1, "stroustrup", { "allowSingleLine": true }], - // 小括号中的空格 - "space-in-parens": [1, "never"], - - } -}; + env: { + es6: true, + browser: true, + node: true, + }, + ecmaFeatures: { + modules: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + globals: { + wx: true, + App: true, + Page: true, + getCurrentPages: true, + getApp: true, + Component: true, + requirePlugin: true, + requireMiniProgram: true, + }, + // extends: 'eslint:recommended', + rules: {}, +} diff --git a/.gitignore b/.gitignore index daf9fc9..14ea590 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,14 @@ -.idea/* +# Windows +[Dd]esktop.ini +Thumbs.db +$RECYCLE.BIN/ + +# macOS .DS_Store -.swp +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes + +# Node.js node_modules/ -build/ -.cache/ -emedia_for_wx/ -src/miniprogram_npm/* -src/emedia/webrtc/* diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 11305b5..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,123 +0,0 @@ -# 版本更新说明: -## ## v3.3.0 @ 2020-9-16 -[IM SDK] 增加支持 promise -[IM SDK] 增加 onContactInvited、onContactDeleted、onContactAdded、onContactRefuse、onContactAgreed 好友相关的回调 -[IM SDK] 增加 addContact、deleteContact、acceptInvitation、declineInvitation 代替原subscribe、removeRoster、subscribed、unsubscribed 好友操作 API -[IM SDK] 增加状态码 40,在 onError 中 type 为 40 会回调出因为socket断开导致发送失败的消息 -[IM SDK] 修改默认的resource,以便区分web端和小程序端的用户 -[IM SDK] 修改 getChatRooms 获取聊天室 API,去掉 apiUrl 参数 -[IM SDK] 修改 构造 cmd 消息 API, 去掉 msg 参数 -[IM SDK] 优化构造消API,使用 chatType 来区分消息类型(单聊/群聊/聊天室) -[IM SDK] 修复发送位置消息成功后并不执行 success 回调 -[IM SDK] 增加容错处理 -[demo] 修复小程序断网时发送单聊消息,未有发送成功和发送失败的区分。 - -## v3.2.2 @ 2020-8-25 -[IM SDK] 创建群组增加是否同意参数参数 -[IM SDK] 修复头条小程序消息延迟 -[IM SDK] onError回调增加 error message - -## v3.1.6 @ 2020-07-03 -[音视频 SDK] 增加joinRoom api -[demo] 部分机型在视频会议时被来电打断后,无法继续推拉流,此时自动退出会议。 - - -## v3.1.4 @ 2020-06-11 -[IM SDK] 支持附件下载重定向 -[IM SDK] 支持图片检测违规抛出单独的异常 -[IM SDK] 增加分页获取聊天室成员api -[IM SDK] 修复收消息有延迟情况 -[音视频 SDK] 增加断网重连 -[demo] 用户删除小程序用户,小程序未实时更新,必须切换下页面联系人才会更新 -[demo] 微信版本小程序,联系人界面下拉界面后,切换其他界面无效 -[demo] 其他用户邀请小程序加入群组中,其他用户在群组中发消息,小程序聊天列表中未显示消息 -[demo] 增加对不合法图片的提示 - - -## v3.1.2 @ 2020-05-14 -### Feature -+ [IM SDK] 增加上传修改群/聊天室公告、获取群/聊天室公告、上传/下载/删除群/聊天室文件、获取群/聊天室文件列表, 增加上传修改群/聊天室公告、获取群/聊天室公告、上传/下载/删除群/聊天室文件、获取群/聊天室文件列表 -+ [IM SDK] 修改重连间隔 -+ [IM SDK] 去掉对上传文件大小的限制, 由服务端来限制 -+ [IM SDK] 修复拉历史消息bug -+ [IM SDK] 修复自定义消息没有time -+ [demo] 增加接受群组邀请功能,可以接收移动端的加群邀请 -+ [demo] 同意好友申请后还会反向订阅 -+ [demo] 用cover-view代替view 解决有时input内的文字会在toast之上 - - -## v3.1.1 @ 2020-04-28 -### Feature -+ [demo] 适配v3.1.1 IM SDK -+ [IM SDK] 更新私有协议, 与web端统一 -+ [IM SDK] 增加漫游消息api -+ [IM SDK] 增加聊天室禁言、解除禁言、获取禁言列表、加入黑名单、移除黑名单、获取黑明单列表等api -+ [IM SDK] 增加聊天室、群组一键禁言、白名单等api -+ [IM SDK] 增加发送自定义消息 -+ [IM SDK] 增加群组回执 -+ [音视频 SDK] 兼容 v3.1.1 IM SDK -+ [音视频 SDK] 增加关闭摄像头的回调事件 -+ [音视频 SDK] 修复不能销毁会议 - -demo从 IM SDK 2.0 升级 3.0涉及改动: -1、去掉 setPrensense 方法 -2、查询群组更换api为 getGroup -3、Jid 与2.0不同,变为对象,需要自己拼成字符串 -4、listgroupmemeber、getGroupInfo 返回 res.data 不是res.data.data -5、leaveGroupBySelf退出群、删除好友api变化 -6、addGroupMembers邀请入群变为inviteToGroup -7、注册utils.registerUser变为conn.registerUser -8、xmppURL以及小程序后台socket域名变为wss://im-api-wechat.easemob.com/websocket - -=====3.0======= - -## v1.0.1 @ 2017-07-17 - -### Feature - -* [sdk] 新增加入聊天室接口(joinChatRoom) -* [sdk] 新增成员加入聊天室的回调(memberJoinChatRoomSuccess) -* [demo] 新增发送位置消息功能 -* [demo] 新增浏览收到的小视频功能 - -## v1.1.0 @ 2019-03-22 -### Feature -+ [sdk] [demo] 增加token登录 -+ [demo] 新版demo,修改ui -+ [demo] 增加搜索功能 -+ [demo] 增加联系人按字母排序 -+ [demo] 增加最近聊天按时间排序 -+ [demo] 增加群组消息提醒 -+ [demo] 增加测滑删除功能 -+ [demo] 增加聊天历史分页 -+ [demo] 增加用户名不区分大小写 -+ [demo] 增加接收文件消息提示 -+ [demo] 适配iphonex,以及 xs max等机型 -+ [demo] 主页面由联系人页改为聊天页 -+ [bug] 修改A给好友B发语音消息,B没有显示语音的未读消息数 -+ [bug] iOS聊天界点击输入框进行输入时历史消息展示不合理 -+ [bug] iOS端小程序收到消息时,会话界面来消息的提醒有时会没有提醒,只显示消息数 -+ [bug] 语音消息时长为0 - -## v1.1.1 @ 2019-04-10 -### Feature -+ [sdk] 增加重连机制 -+ [demo] 实时更新联系人列表 -+ [bug] 修复部分已知bug - -## v1.2.0 @ 2019-06-22 -### Feature -+ 增加消息状态,比如断网时发的消息显示失败。 -+ 增加socket连接成功的提示 -+ 修改了语音消息播放时再下载 -+ 修复聊天页面切后台,再切前台收到的离线消息有重复 -+ 由rest1迁移到rest2后开始校验token,导致附件消息收不到 -+ 语音发送成功后点击听取后,语音依然闪烁动画 -+ 联系人分类为#,显示问题。 -+ sdk增加onSocketConnected事件 – socket连接成功 -+ sdk onError 增加type='sendMsgError'发送消息失败 -+ sdk 重连时关闭上次的socket - -## v1.3.0 @ 2020-02-10 -### Feature -+ 增加音视频会议功能 diff --git a/src/sdk/Easemob-chat-4.9.1.js b/EaseIM/Easemob-chat.js similarity index 100% rename from src/sdk/Easemob-chat-4.9.1.js rename to EaseIM/Easemob-chat.js diff --git a/EaseIM/config/index.js b/EaseIM/config/index.js new file mode 100644 index 0000000..3806b55 --- /dev/null +++ b/EaseIM/config/index.js @@ -0,0 +1,5 @@ +export const EM_API_URL = 'https://a1.easemob.com'; +export const EM_WEB_SOCKET_URL = 'wss://im-api-wechat.easemob.com/websocket'; +export const EM_APP_KEY = 'easemob#easeim'; +// export const EM_APP_KEY = 'easemob-demo#support'; +// export const EM_APP_KEY = 'easemob-demo#support'; diff --git a/EaseIM/constant/grayInform.js b/EaseIM/constant/grayInform.js new file mode 100644 index 0000000..84f3e68 --- /dev/null +++ b/EaseIM/constant/grayInform.js @@ -0,0 +1,36 @@ +/** + * 此常量非SDK内置,而是基于SDK回调事件演化而来, + * 用于在聊天界面能够展示灰色小字通知 + * 如不需要,可以不做引入。 + * */ +//灰色通知好友类型 +export const GRAY_INFORM_TEMPLATE_NAME = { + USER: '[XXX]', + GROUP_USER_FROM: '[AXX]', + GROUP_USER_TO: '[BXX]', + GROUP_ID: '[X_GROUP_ID_X]', +}; +export const GRAY_INFORM_TYPE_SINGLE = { + CONTACT_ADDED: 'contactAdded', + CONTACT_AGREED: 'contactAgreed', +}; +//灰色通知对应好友文本展示,[XXX]用于替换为实际用户ID或昵称 +export const GRAY_INFORM_MAP_SINGLE_TEXT = { + [GRAY_INFORM_TYPE_SINGLE.CONTACT_ADDED]: `你已添加了${GRAY_INFORM_TEMPLATE_NAME.USER},打个招呼吧!`, + [GRAY_INFORM_TYPE_SINGLE.CONTACT_AGREED]: `${GRAY_INFORM_TEMPLATE_NAME.USER}通过了你的好友申请,打个招呼吧!`, +}; +//灰色通知群聊 +export const GRAY_INFORM_TYPE_GROUP = { + MEMBER_PRESENCE: 'memberPresence', // 有用户加入群组。除了新成员,其他群成员会收到该回调。 + MEMBER_ABSENCE: 'memberAbsence', //群成员主动退出群组 + CHANGE_OWNER: 'changeOwner', // 转让群组。原群主和新群主会收到该回调。 + MEMBER_REMOVE: 'removeMember', // 用户被移出群组。被踢出群组的成员会收到该回调。 +}; + +export const GRAY_INFORM_MAP_GROUP_TEXT = { + [GRAY_INFORM_TYPE_GROUP.MEMBER_PRESENCE]: `${GRAY_INFORM_TEMPLATE_NAME.GROUP_USER_FROM}加入了群组`, + [GRAY_INFORM_TYPE_GROUP.MEMBER_ABSENCE]: `${GRAY_INFORM_TEMPLATE_NAME.GROUP_USER_FROM}退出了群组`, + // [GRAY_INFORM_TYPE_GROUP.CHANGE_OWNER]: `${GRAY_INFORM_TEMPLATE_NAME.GROUP_USER_FROM}移交群主至${GRAY_INFORM_TEMPLATE_NAME.GROUP_USER_TO}`, + [GRAY_INFORM_TYPE_GROUP.CHANGE_OWNER]: `${GRAY_INFORM_TEMPLATE_NAME.GROUP_USER_FROM}将群主移交`, + [GRAY_INFORM_TYPE_GROUP.MEMBER_REMOVE]: `您已被移出${GRAY_INFORM_TEMPLATE_NAME.GROUP_ID}该群组!`, +}; diff --git a/EaseIM/constant/index.js b/EaseIM/constant/index.js new file mode 100644 index 0000000..e459f9f --- /dev/null +++ b/EaseIM/constant/index.js @@ -0,0 +1,177 @@ +import { + GRAY_INFORM_TYPE_SINGLE, + GRAY_INFORM_MAP_SINGLE_TEXT, + GRAY_INFORM_TYPE_GROUP, + GRAY_INFORM_MAP_GROUP_TEXT, + GRAY_INFORM_TEMPLATE_NAME, +} from './grayInform'; +/* 灰色通知类型 */ +export { + GRAY_INFORM_TYPE_SINGLE, + GRAY_INFORM_MAP_SINGLE_TEXT, + GRAY_INFORM_TYPE_GROUP, + GRAY_INFORM_MAP_GROUP_TEXT, + GRAY_INFORM_TEMPLATE_NAME, +}; +export const CHAT_TYPE = { + SINGLE_CHAT: 'singleChat', + GROUP_CHAT: 'groupChat', +}; +export const INFORM_TYPE = { + CONTACTS: 'contacts', + GROUPS: 'groups', +}; +export const HANDLER_EVENT_NAME = { + CONNECT_EVENT: 'connectEvent', + MESSAGES_EVENT: 'messagesEvent', + CONTACTS_EVENT: 'contactsEvent', + GROUP_EVENT: 'groupEvent', + ERROR_EVENT: 'errorEvent', + PRESENCE_EVENT: 'presenceEvent', +}; + +export const CONNECT_CALLBACK_TYPE = { + CONNECT_CALLBACK: 'connected', + DISCONNECT_CALLBACK: 'disconnected', + RECONNECTING_CALLBACK: 'reconnecting', + ERROR_CALLBACK: 'onerror', +}; +//定义消息状态 +export const MESSAGE_STATUS = { + READ: 'read', + UNREAD: 'unread', + DELETE: 'deleted', + PENDING: 'pending', + RECALL: 'recalled', + FAIL: 'fail', +}; +export const MESSAGE_TYPE = { + IMAGE: 'img', + TEXT: 'txt', + LOCATION: 'loc', + VIDEO: 'video', + AUDIO: 'audio', + EMOJI: 'emoji', + FILE: 'file', + CUSTOM: 'custom', + CMD: 'cmd', + GRAY_INFORM: 'gray_inform', //此类型非SDK正式类型,此类型为自定义的本地插入用于灰色通知类型。 +}; +export const SESSION_MESSAGE_TYPE = { + [MESSAGE_TYPE.IMAGE]: '[图片]', + [MESSAGE_TYPE.FILE]: '[文件]', + [MESSAGE_TYPE.AUDIO]: '[语音]', + [MESSAGE_TYPE.LOCATION]: '[位置]', + [MESSAGE_TYPE.VIDEO]: '[视频]', +}; +export const CUSTOM_EVENT_NAME = { + USER_CARD: 'userCard', +}; +export const CUSTOM_TYPE = { + [CUSTOM_EVENT_NAME.USER_CARD]: '个人名片', +}; + +export const EMOJI = { + path: '@/static/images/faces', + map: { + '[):]': 'ee_1.png', + '[:D]': 'ee_2.png', + '[;)]': 'ee_3.png', + '[:-o]': 'ee_4.png', + '[:p]': 'ee_5.png', + '[(H)]': 'ee_6.png', + '[:@]': 'ee_7.png', + '[:s]': 'ee_8.png', + '[:$]': 'ee_9.png', + '[:(]': 'ee_10.png', + "[:'(]": 'ee_11.png', + '[ { + // 处理未读消息回执 + const sendReadAckMsg = (receivemsg) => { + const { chatType, from, id } = receivemsg; + let option = { + type: 'read', // 消息是否已读。 + chatType: chatType, // 会话类型,这里为单聊。 + to: from, // 消息接收方的用户 ID。 + id: id, // 需要发送已读回执的消息 ID。 + }; + let msg = EaseSDK.message.create(option); + EMClient.send(msg); + }; + //发送撤回ack + const sendRecallAckMsg = (recallSourceMsg) => { + const { chatType, to, id } = recallSourceMsg; + let option = { + // 要撤回消息的消息 ID。 + mid: id, + // 消息接收方:单聊为对方用户 ID,群聊和聊天室分别为群组 ID 和聊天室 ID。 + to: to, + // 会话类型:单聊、群聊和聊天室分别为 `singleChat`、`groupChat` 和 `chatRoom`。 + chatType: chatType, + }; + return new Promise((resolve, reject) => { + EMClient.recallMessage(option) + .then((res) => { + console.log('recall success', res); + resolve(res); + }) + .catch((error) => { + // 消息撤回失败,原因可能是超过了撤销时限(超过 2 分钟)。 + console.log('fail', error); + reject(error); + }); + }); + }; + return { + sendReadAckMsg, + sendRecallAckMsg, + }; +}; + +export default emSendReadAck; diff --git a/EaseIM/emApis/emConnect.js b/EaseIM/emApis/emConnect.js new file mode 100644 index 0000000..3c18ff2 --- /dev/null +++ b/EaseIM/emApis/emConnect.js @@ -0,0 +1,38 @@ +import { EMClient } from '../index'; +const emConnect = () => { + const loginWithPassword = (hxUserId, hxPassword) => { + if (!hxUserId || !hxPassword) throw Error('empty params'); + return new Promise((resolve, reject) => { + EMClient.open({ + user: hxUserId, + pwd: hxPassword, + }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const loginWithAccessToken = (hxUserId, hxAccessToken) => { + if (!hxUserId || !hxAccessToken) throw Error('empty params'); + return new Promise((resolve, reject) => { + EMClient.open({ + user: hxUserId, + accessToken: hxAccessToken, + }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const closeEaseIM = () => { + EMClient.close(); + }; + return { + loginWithPassword, + loginWithAccessToken, + closeEaseIM, + }; +}; +export default emConnect; diff --git a/EaseIM/emApis/emContacts.js b/EaseIM/emApis/emContacts.js new file mode 100644 index 0000000..8b47bfb --- /dev/null +++ b/EaseIM/emApis/emContacts.js @@ -0,0 +1,130 @@ +import { EMClient } from '../index'; +const emContacts = () => { + const fetchContactsListFromServer = () => { + return new Promise((resolve, reject) => { + EMClient.getAllContacts() + .then((res) => { + const { data } = res; + console.log('>>>>>获取全部好友列表'); + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const removeContactFromServer = (contactId) => { + if (contactId) { + return new Promise((resolve, reject) => { + EMClient.deleteContact(contactId) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + } + }; + const addContactFromServer = (contactId, applyMsg = '加个好友吧') => { + if (contactId) { + return new Promise((resolve, reject) => { + EMClient.addContact(contactId, applyMsg) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + } + }; + + const acceptContactInvite = (contactId) => { + if (contactId) { + return new Promise((resolve, reject) => { + EMClient.acceptContactInvite(contactId) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + // EMClient.acceptContactInvite(contactId); + } + }; + const declineContactInvite = (contactId) => { + if (contactId) { + return new Promise((resolve,reject)=>{ + EMClient.declineContactInvite(contactId).then(res=>{ + resolve(res) + }).catch(error=>{ + reject(error) + }) + }) + + } + }; + const getBlocklistFromServer = () => { + return new Promise((resolve, reject) => { + EMClient.getBlocklist() + .then((res) => { + const { data } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const addUsersToBlocklist = (userList) => { + return new Promise((resolve, reject) => { + EMClient.addUsersToBlocklist({ name: [...userList] }) + .then((res) => { + const { data } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const removeUsersFromBlocklist = (userList) => { + return new Promise((resolve, reject) => { + EMClient.removeUserFromBlocklist({ name: [...userList] }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const setContactRemarkFromServer = (contactId, remark) => { + return new Promise((resolve, reject) => { + EMClient.setContactRemark({ + userId: contactId, + remark, + }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + return { + fetchContactsListFromServer, + removeContactFromServer, + addContactFromServer, + acceptContactInvite, + declineContactInvite, + getBlocklistFromServer, + addUsersToBlocklist, + removeUsersFromBlocklist, + setContactRemarkFromServer, + }; +}; +export default emContacts; diff --git a/EaseIM/emApis/emConversation.js b/EaseIM/emApis/emConversation.js new file mode 100644 index 0000000..b98ef71 --- /dev/null +++ b/EaseIM/emApis/emConversation.js @@ -0,0 +1,90 @@ +import { EaseSDK, EMClient } from '../index'; +import { CHAT_TYPE } from '../constant/index'; +const emConversation = () => { + //从服务端获取置顶会话列表 + const fetchPinConversationFromServer = (pageSize = 50, cursor = '') => { + return new Promise((resolve, reject) => { + EMClient.getServerPinnedConversations({ pageSize, cursor }) + .then((res) => { + console.log('>>>>置顶会话列表数据获取成功'); + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //置顶会话列表 + const pinConversationItem = (params) => { + const { conversationId, conversationType, isPinned } = params; + return new Promise((resolve, reject) => { + EMClient.pinConversation({ + conversationId, + conversationType, + isPinned, + }) + .then((res) => { + console.log('>>>>置顶会话列表添加成功'); + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //从服务端获取会话列表 + const fetchConversationFromServer = ( + options = { pageSize: 50, cursor: '' } + ) => { + return new Promise((resolve, reject) => { + // 支持分页这里写死 + EMClient.getServerConversations({ ...options }) + .then((res) => { + console.log('>>>>会话列表数据获取成功'); + const result = res.data; + resolve(result); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //从服务端删除会话 + const removeConversationFromServer = ( + channel, + chatType = CHAT_TYPE.SINGLE_CHAT, + deleteRoam = false + ) => { + if (!channel) return; + return new Promise((resolve, reject) => { + EMClient.deleteConversation({ channel, chatType, deleteRoam }) + .then((res) => { + console.log('>>>>会话删除成功'); + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //发送会话已读回执 + const sendChannelAck = (targetId, chatType = CHAT_TYPE.SINGLE_CHAT) => { + if (!targetId) return; + let option = { + chatType: chatType, // 会话类型,设置为单聊。 + type: 'channel', // 消息类型。 + to: targetId, // 接收消息对象的用户 ID。 + }; + const msg = EaseSDK.message.create(option); + EMClient.send(msg); + }; + return { + fetchPinConversationFromServer, + pinConversationItem, + fetchConversationFromServer, + removeConversationFromServer, + sendChannelAck, + }; +}; + +export default emConversation; diff --git a/EaseIM/emApis/emGroups.js b/EaseIM/emApis/emGroups.js new file mode 100644 index 0000000..1144830 --- /dev/null +++ b/EaseIM/emApis/emGroups.js @@ -0,0 +1,265 @@ +import { EMClient } from '../index'; +const emGroups = () => { + const fetchJoinedGroupListFromServer = (pageNum = 0, pageSize = 20) => { + return new Promise((resolve, reject) => { + console.log('>>>>开始获取加入的群组列表'); + EMClient.getJoinedGroups({ + pageNum, + pageSize, + needAffiliations: true, + needRole: true, + }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const createNewGroup = (params) => { + return new Promise((resolve, reject) => { + console.log('>>>>开始创建群组'); + EMClient.createGroup({ data: { ...params } }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const getGroupInfosFromServer = (groupId) => { + return new Promise((resolve, reject) => { + EMClient.getGroupInfo({ + groupId, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const getGroupMembersFromServer = (groupId,pageNum=1,pageSize=100) => { + //暂且仅取前100个群成员 + // const pageNum = 1, + // pageSize = 100; + return new Promise((resolve, reject) => { + EMClient.listGroupMembers({ + pageNum: pageNum, + pageSize: pageSize, + groupId, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const inviteUsersToGroup = (groupId, memberIdList) => { + return new Promise((resolve, reject) => { + EMClient.inviteUsersToGroup({ + groupId: groupId, + users: memberIdList, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const leaveGroupFromServer = (groupId) => { + return new Promise((resolve, reject) => { + EMClient.leaveGroup({ groupId }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const destroyGroupFromServer = (groupId) => { + return new Promise((resolve, reject) => { + EMClient.destroyGroup({ groupId }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const acceptGroupInvite = (invitee, groupId) => { + return new Promise((resolve, reject) => { + EMClient.acceptGroupInvite({ + groupId: groupId, + invitee: invitee, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const rejectGroupInvite = (invitee, groupId) => { + return new Promise((resolve, reject) => { + EMClient.rejectGroupInvite({ + groupId: groupId, + invitee: invitee, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const joinPublicGroup = (groupId) => { + return new Promise((resolve, reject) => { + EMClient.joinGroup({ groupId, message: 'I want to join the group' }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const modifyGroupInfo = (groupId, params) => { + return new Promise((resolve, reject) => { + EMClient.modifyGroup({ + groupId, + ...params, + }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const removeGroupMembers = (groupId, users) => { + return new Promise((resolve, reject) => { + EMClient.removeGroupMembers({ + groupId, + users, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const changeGroupOwner = (groupId, newOwner) => { + return new Promise((resolve, reject) => { + EMClient.changeGroupOwner({ groupId, newOwner }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //分页获取群组列表 + const listGroupMembersFromServer = (params) => { + const { pageNum = 1, pageSize = 100, groupId } = params; + return new Promise((resolve, reject) => { + EMClient.listGroupMembers({ + ...params, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + /* 群组属性相关 */ + //获取单个用户属性 + const getSingleGroupAttributesFromServer = (groupId, userId) => { + let options = { + groupId, + userId, + }; + return new Promise((resolve, reject) => { + EMClient.getGroupMemberAttributes({ ...options }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //设置单个群组属性 + const setSingleGroupAttributesFromServer = (params) => { + const { groupId, userId, memberAttributes } = params; + return new Promise((resolve, reject) => { + EMClient.setGroupMemberAttributes({ + groupId, + userId, + memberAttributes: { ...memberAttributes }, + }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + //根据key获取多个群组成员自定义属性 + const getMultiGroupAttributesFromServer = (params) => { + const { groupId, userIds, keys } = params; + return new Promise((resolve, reject) => { + EMClient.getGroupMembersAttributes({ + groupId, + userIds, + keys, + }) + .then((res) => { + resolve(res.data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + + return { + fetchJoinedGroupListFromServer, + createNewGroup, + getGroupInfosFromServer, + getGroupMembersFromServer, + inviteUsersToGroup, + leaveGroupFromServer, + destroyGroupFromServer, + acceptGroupInvite, + rejectGroupInvite, + joinPublicGroup, + modifyGroupInfo, + changeGroupOwner, + removeGroupMembers, + listGroupMembersFromServer, + getSingleGroupAttributesFromServer, + getMultiGroupAttributesFromServer, + setSingleGroupAttributesFromServer, + }; +}; + +export default emGroups; diff --git a/EaseIM/emApis/emMessages.js b/EaseIM/emApis/emMessages.js new file mode 100644 index 0000000..95149ef --- /dev/null +++ b/EaseIM/emApis/emMessages.js @@ -0,0 +1,86 @@ +import { EaseSDK, EMClient } from '../index'; +import { MESSAGE_TYPE } from '../constant/index'; +const emMessages = () => { + const reportMessages = (params) => { + const { reportType, reportReason, messageId } = params; + return new Promise((resolve, reject) => { + EMClient.reportMessage({ + reportType: reportType, // 举报类型 + reportReason: reportReason, // 举报原因。 + messageId: messageId, // 上报消息id + }) + .then((res) => { + resolve(res); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const fetchHistoryMessagesFromServer = (params) => { + const { targetId, cursor, chatType } = params; + return new Promise((resolve, reject) => { + let options = { + // 对方的用户 ID 或者群组 ID 或聊天室 ID。 + targetId: targetId, + // 每页期望获取的消息条数。取值范围为 [1,50],默认值为 20。 + pageSize: 50, + // 查询的起始消息 ID。若该参数设置为 `-1`、`null` 或空字符串,从最新消息开始。 + cursor: cursor || -1, + // 会话类型:(默认) `singleChat`:单聊;`groupChat`:群聊。 + chatType: chatType, + // 消息搜索方向:(默认)`up`:按服务器收到消息的时间的逆序获取;`down`:按服务器收到消息的时间的正序获取。 + searchDirection: 'up', + }; + EMClient.getHistoryMessages(options) + .then((res) => { + resolve(res); + }) + .catch((e) => { + // 获取失败。 + reject(e); + }); + }); + }; + const sendCommandMessages = (messageBody) => { + return new Promise((resolve, reject) => { + console.log('messageBody', messageBody); + const message = EaseSDK.message.create(messageBody); + console.log('>>>>构建的命令消息msg', message); + EMClient.send(message) + .then((res) => { + resolve(res); + }) + .catch((e) => { + reject(e); + }); + }); + }; + //修改展示类消息【暂只支持文本消息】 + const modifyDisplayMessages = (messageBody) => { + const { msg, to, id, chatType } = messageBody; + const textMessage = EaseSDK.message.create({ + type: MESSAGE_TYPE.TEXT, + msg: msg, + to: to, + chatType: chatType, + }); + return new Promise((resolve, reject) => { + EMClient.modifyMessage({ messageId: id, modifiedMessage: textMessage }) + .then((res) => { + resolve(res); + }) + .catch((e) => { + console.log(e); + reject(e); + }); + }); + }; + return { + reportMessages, + fetchHistoryMessagesFromServer, + sendCommandMessages, + modifyDisplayMessages, + }; +}; +export default emMessages; diff --git a/EaseIM/emApis/emPresence.js b/EaseIM/emApis/emPresence.js new file mode 100644 index 0000000..469f542 --- /dev/null +++ b/EaseIM/emApis/emPresence.js @@ -0,0 +1,136 @@ +import { + EaseSDK, + EMClient +} from '../index'; +const _chunkArr = (oldArr, num) => { + oldArr.sort((a, b) => { + return a - b; + }); + if (oldArr.length <= 0) return oldArr; + let newArr = []; + if (Math.ceil(oldArr.length / num) <= 1) { + newArr.push(oldArr); + return newArr; + } + for (let i = 0; i < oldArr.length; i = i + num) { + newArr.push(oldArr.slice(i, i + num)); + } + return newArr; +}; +const emPresence = () => { + // 发布自定义在线状态 + const publishPresence = (presenceMsg) => { + return new Promise((resolve, reject) => { + EMClient.publishPresence({ + description: presenceMsg, + + }) + .then((res) => { + resolve(res) + }) + .catch((error) => { + reject(error); + }); + }); + }; + // 订阅用户的在线状态 + const subscribePresence = (userList) => { + let friendList = []; + friendList = Object.assign([], userList); + return new Promise((resolve, reject) => { + if (friendList.length && friendList.length < 99) { + EMClient.subscribePresence({ + usernames: friendList, + expiry: 7 * 24 * 3600 + }) + .then((res) => { + const { + data + } = res; + resolve(data.result); + }) + .catch((error) => { + reject(error); + }); + } else { + let newArr = _chunkArr(friendList, 99); + for (let i = 0; i < newArr.length; i++) { + EMClient.subscribePresence({ + usernames: newArr[i], + expiry: 7 * 24 * 3600 + } ) + .then((res) => { + const { + data + } = res; + resolve(data.result); + }) + .catch((error) => { + reject(error); + }); + } + } + }); + }; + // 获取用户的当前在线状态 + const getPresenceStatus = (userList) => { + let friendList = []; + friendList = Object.assign([], userList); + return new Promise((resolve, reject) => { + if (friendList.length && friendList.length < 99) { + EMClient.getPresenceStatus({ + usernames: friendList + }) + .then((res) => { + const { + data + } = res; + resolve(data.result); + }) + .catch((error) => { + reject(error); + }); + } else { + let newArr = _chunkArr(friendList, 99); + for (let i = 0; i < newArr.length; i++) { + EMClient.getPresenceStatus({ + usernames: newArr[i] + }) + .then((res) => { + const { + data + } = res; + resolve(data.result); + }) + .catch((error) => { + reject(error); + }); + } + } + }); + }; + // 取消订阅 + const unsubscribePresence = (userName) => { + return new Promise((resolve, reject) => { + EMClient.unsubscribePresence({ + usernames: [userName] + + }) + .then((res) => { + console.log("取消订阅成功") + resolve(res) + }) + .catch((error) => { + reject(error); + }); + }); + }; + return { + publishPresence, + subscribePresence, + getPresenceStatus, + unsubscribePresence + }; +}; + +export default emPresence; \ No newline at end of file diff --git a/EaseIM/emApis/emSilent.js b/EaseIM/emApis/emSilent.js new file mode 100644 index 0000000..d33b172 --- /dev/null +++ b/EaseIM/emApis/emSilent.js @@ -0,0 +1,72 @@ +import { EMClient } from '../index'; +const emSilent = () => { + const getSilentModeForConversation = (conversationId, type) => { + return new Promise((resolve, reject) => { + EMClient.getSilentModeForConversation({ + conversationId, + type, + }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const getSilentModeForConversationList = (conversationList) => { + return new Promise((resolve, reject) => { + EMClient.getSilentModeForConversations({ conversationList }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const getSilentModeForAll = () => { + return new Promise((resolve, reject) => { + EMClient.getSilentModeForAll() + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const setSilentModeForAll = ({ paramType = 0, remindType = 'ALL' }) => { + return new Promise((resolve, reject) => { + EMClient.setSilentModeForAll({ options: { paramType, remindType } }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const setSilentModeForConversation = (params) => { + const { conversationId, type, options } = params; + return new Promise((resolve, reject) => { + EMClient.setSilentModeForConversation({ conversationId, type, options }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + const clearRemindTypeForConversation = (params) => { + const { conversationId, type } = params; + return new Promise((resolve, reject) => { + EMClient.clearRemindTypeForConversation({ conversationId, type }) + .then((res) => { + resolve(res); + }) + .catch((err) => reject(err)); + }); + }; + return { + getSilentModeForAll, + setSilentModeForAll, + getSilentModeForConversation, + getSilentModeForConversationList, + setSilentModeForConversation, + clearRemindTypeForConversation, + }; +}; + +export default emSilent; diff --git a/EaseIM/emApis/emUserInfos.js b/EaseIM/emApis/emUserInfos.js new file mode 100644 index 0000000..6be48c0 --- /dev/null +++ b/EaseIM/emApis/emUserInfos.js @@ -0,0 +1,104 @@ +import { + EMClient +} from '../index'; +const _chunkArr = (oldArr, num) => { + oldArr.sort((a, b) => { + return a - b; + }); + if (oldArr.length <= 0) return oldArr; + let newArr = []; + if (Math.ceil(oldArr.length / num) <= 1) { + newArr.push(oldArr); + return newArr; + } + for (let i = 0; i < oldArr.length; i = i + num) { + newArr.push(oldArr.slice(i, i + num)); + } + return newArr; +}; + +const emUserInofs = () => { + const fetchUserInfoWithLoginId = () => { + const userId = EMClient.user; + return new Promise((resolve, reject) => { + if (userId) { + EMClient.fetchUserInfoById(userId) + .then((res) => { + const { + data + } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + } + }); + }; + const fetchOtherInfoFromServer = (userList) => { + let friendList = []; + friendList = Object.assign([], userList); + return new Promise((resolve, reject) => { + if (friendList.length && friendList.length < 99) { + EMClient.fetchUserInfoById(friendList) + .then((res) => { + const { + data + } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + } else { + let newArr = _chunkArr(friendList, 99); + for (let i = 0; i < newArr.length; i++) { + EMClient.fetchUserInfoById(newArr[i]) + .then((res) => { + const { + data + } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + } + } + }); + }; + const updateUserInfosFromServer = (params) => { + return new Promise((resolve, reject) => { + EMClient.updateUserInfo({ + ...params + }) + .then((res) => { + const { + data + } = res; + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); + }; + const updateLoginUserInfos = (params) => { + return new Promise((resolve, reject) => { + EMClient.updateUserInfo({ + ...params + }).then((res) => { + resolve(res) + }).catch(err => { + reject(err) + }) + }) + } + return { + fetchUserInfoWithLoginId, + fetchOtherInfoFromServer, + updateUserInfosFromServer, + updateLoginUserInfos + }; +}; +export default emUserInofs; \ No newline at end of file diff --git a/EaseIM/emApis/index.js b/EaseIM/emApis/index.js new file mode 100644 index 0000000..5b125a6 --- /dev/null +++ b/EaseIM/emApis/index.js @@ -0,0 +1,20 @@ +import emConnect from './emConnect/index'; +import emUserInfos from './emUserInfos/index'; +import emContacts from './emContacts/index'; +import emGroups from './emGroups/index'; +import emAboutAck from './emAboutAck/index'; +import emConversation from './emConversation/index'; +import emMessages from './emMessages/index'; +import emSilent from './emSilent/index'; +import emPresence from './emPresence/index'; +export { + emConnect, + emUserInfos, + emContacts, + emGroups, + emAboutAck, + emConversation, + emMessages, + emSilent, + emPresence +}; diff --git a/EaseIM/index.js b/EaseIM/index.js new file mode 100644 index 0000000..65fedeb --- /dev/null +++ b/EaseIM/index.js @@ -0,0 +1,11 @@ +import EaseSDK from './Easemob-chat'; +import { EM_APP_KEY, EM_API_URL, EM_WEB_SOCKET_URL } from './config/index'; +let EMClient = (wx.EMClient = {}); +EMClient = new EaseSDK.connection({ + appKey: EM_APP_KEY, + apiUrl: EM_API_URL, + url: EM_WEB_SOCKET_URL, + enableReportLogs: true, //小程序平台(uniApp)开启日志上传。 +}); +wx.EMClient = EMClient; +export { EaseSDK, EMClient }; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f1fa233 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 NeoHuang(黄飞鹏) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/READEME.md b/READEME.md new file mode 100644 index 0000000..a2f6b96 --- /dev/null +++ b/READEME.md @@ -0,0 +1,77 @@ +# 简介 + +> `webim-wechat-miniprogram-demo`属于是相对最近的环信小程序 SDK 集成方式演示项目,此示例供集成微信小程序实现 IM 功能做为参考示例项目,在该项目中通过使用`vant-weapp`加快 UI 逻辑搭建,并使用`mobx`进行部分全局状态管理。 + +# 运行 + +> 此项目可以在微信开发者工具中直接导入并点击编译进行项目预览。 + +# 效果预览 + +## 登录页面 + + + +## 会话页 + + + +## 联系人 + + + +## 我的 + + + +## 群组 + + + +## 群组成员 + + + +## 群组详情 + + + +## 聊天页 + + + +## 发送语音 + + + +## 发送图片(视频) + + + +## 发送表情 + + + +## 长按消息 + + + +更多功能请下载体验,并会持续更新... + +# 扩展内容 + +## 针对引入 vant-weapp 未使用组件进行 tree-sharing + +> 首先需要执行 npm install 并安装 `vant-tree-shaking`在使用`vatn-weapp`集成后,再执行下方命令剔除不适用的 UI 组件。 + +```shell +npm run vant-t +``` + +## vant-weapp 的引入 + +### 安装 vant-weapp 组件 + +```shell +npm i @vant/weapp -S --production +``` diff --git a/README.md b/README.md deleted file mode 100644 index 222aa5d..0000000 --- a/README.md +++ /dev/null @@ -1,113 +0,0 @@ -# 介绍 -****** -环信小程序demo是基于环信im SDK开发的一款即时通讯的小程序。这个demo可以帮助开发者们更轻松的集成环信SDK。可扫码体验: -![huanxinIM](./src/images/huanxindemo.jpg) -demo 包含以下功能 - - 最近通话 - - 通讯录 - - 通知(加好友、加群) - - 设置 -# 在本地跑起来 -拉取代码,导入开发者工具即可运行起来。 - -# 数据结构 -``` -登录页: - login: { - name:'', - psd: '', - grant_type: 'password', - } - -注册页: - register: { - username: '', - password: '' - } - -通讯录页: - member:[], //好友列表 - -聊天页: - chatMsg:[{ - info:{ - to:'' - }, - username:'', //用户名 - yourname:'', //好友名 - msg: { - type:'', - data:'' - }, - style:'', //样式 - time:'', - mid:'' //message ID - }] - -globalData: - userInfo: '', //用户微信授权信息 - chatMsg: [] //用于存储离线消息 - unReadMessageNum: 0, //未读消息数 - saveFriendList: [],//加好友申请 - saveGroupInvitedList: [], //加群邀请 - isIPX: false //是否为iphone X //是否为iphoneX - -缓存: - myUsername: '' //缓存登录用户名 - yourname + myName:'' //以用户名跟好友名为key来缓存聊天记录 -``` -# 项目结构 -```shell -|- comps 自定义组件目录 - |- addfriend 添加好友页 - |-chat 聊天页面 - |-swipedelete 测滑删除 - |-toast toast -|-images demo中用到的图片 还有表情 -|-pages 功能页面 - |-register 注册页 - |-login 登录页 - |-login_token token登录页 - |-chat 最近联系人页(通话) - |-chatroom 聊天室页 - |-main 联系人页 - |-add_new 加好友页 - |-group 群组页 - |-groupSetting 群组设置页 - |-notificaton 通知页 - |-notificaton_friendDetail 加好友通知页 - |-notificaton_groupDetail 加群组通知页 - |-setting 设置页 - |-setting_general 通用设置页 -|-utils 工具类和sdk的一些配置 -|-sdk 环信sdk -|-app.js 小程序根实例,存放一些全局变量,注册监听事件 -|-app.json 注册页面以及全局的一些配置 -|-app.wxss 一些全局样式 -|-project.config.json工程的一些配置,和开发者工具 “详情” 中的设置一样 -``` -# 可以复用的代码 -如果想快速搭建起一个有im能力的小程序,可以选择复用demo中的代码,其中utils以帮助快速集成sdk,comps > chat是聊天页。当然其他部分需要复用的,如常见的测滑删除、联系人按字母分类、通知的订阅模式也可以去具体文件去找。 - -# 常见问题 -+ 怎么发扩展消息? - - 构造消息的时候msg.set(option), option中传人ext字段,即可发送扩展消息,具体可以查看[文档](http://docs-im.easemob.com/im/applet/message#%E5%8F%91%E9%80%81%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF_%E5%8D%95%E8%81%8A)。 -+ 使用mpvue集成报错? - - .babelrc文件中修改 "plugins": ["transform-es2015-modules-commonjs"],这里有一些开发者的[经验](https://blog.csdn.net/qq_43128835/article/details/95400888)。 -+ 陌生人消息不上屏? - - 目前demo并没有去实现,现在的逻辑是会话列表是从好友列表去查的,可以看pages/chat/chat.js getChatList()。 -# 遇到的一些坑 -- 聊天页面布局,input focus时页面滑动,光标会错位,官方的说法是,input focus时不能使用动画。 -- 在scroll-view中无法触发onPullDownRefresh。 -- margin-bottom 只有在下面还有元素时才生效。 -- 使用enablePullDownRefresh看不见下拉动画,需要将backgroundTextStyle设为dark。 -- 播放语音 onTimeUpdate在开发者工具上不能稳定触发。 -- background-image只能用网络地址。 -- 适配iphone X 使用wx.getSystemInfo() 返回的model在工具上是'iPhone X' 在真机上后面还会有其他字符,不要精确匹配。 - -坑还有很多,大家慢慢趟吧 -# 写在最后 -这期小程序demo只完善了单聊部分,后面还要优化群组的一些功能,关于图片消息缓存的问题,目前图片都是压缩过的,大约在200k左右,如果要做缓存自己可以使用storage去实现,但是要注意小程序只有10M的存储空间,还有一些功能demo没有去实现但是sdk是支持的,要用到的话大家可以去查[文档](https://webim.easemob.com/sdk/jsdoc/out/connection.html) \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..c8db095 --- /dev/null +++ b/app.js @@ -0,0 +1,204 @@ +import { + EMClient +} from "./EaseIM/index" +import { + store +} from './store/index' +App({ + globalData: { + globalActiveTab: 0, + tabbarHeight: 50, + safeAreaBottomHeight: 0 + }, + onLaunch() { + wx.getSystemInfo({ + success: (res) => { + const tabbarHeight = (res.screenHeight - res.safeArea.bottom) + 50 + const safeAreaInsetBottom = res.screenHeight - res.safeArea.bottom + console.log('tabbarHeigth', tabbarHeight) + console.log('safeAreaBottomHeigth', safeAreaInsetBottom); + this.globalData.safeAreaBottomHeight = safeAreaInsetBottom + this.globalData.tabbarHeight = tabbarHeight + } + }) + this.mountEaseIMListener() + }, + mountEaseIMListener() { + console.log('>>>>>>EaseIM Listener'); + /* 连接监听 */ + EMClient.addEventHandler("CONNECT", { + onConnected: () => { + console.log("onConnected"); + }, + // 自 4.8.0 版本,`onDisconnected` 事件新增断开原因回调参数, 告知用户触发 `onDisconnected` 的原因。 + onDisconnected: () => { + console.log("onDisconnected"); + }, + onTokenWillExpire: () => { + console.log("onTokenWillExpire"); + }, + onTokenExpired: () => { + console.log("onTokenExpired"); + }, + }); + /* 消息监听 */ + EMClient.addEventHandler('MESSAGE', { + // 当前用户收到文本消息。 + onTextMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到图片消息。 + onImageMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到透传消息。 + onCmdMessage: (message) => { + // store.updateConversationLastMessage({...message}) + }, + // 当前用户收到语音消息。 + onAudioMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到位置消息。 + onLocationMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到文件消息。 + onFileMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到自定义消息。 + onCustomMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + // 当前用户收到视频消息。 + onVideoMessage: (message) => { + store.updateConversationLastMessage({...message}) + }, + }) + /* 好友关系监听 */ + EMClient.addEventHandler("CONTACTS", { + // 当前用户收到好友邀请。 + onContactInvited: function (msg) { + console.log('收到好友申请事件', msg); + msg.key = msg.from + msg.chatType = 'singleChat' + store.updateNotificationsList({ + ...msg + }) + }, + // 联系人被删除。 + onContactDeleted: function (msg) { + store.initContactsListFromServer() + }, + // 新增联系人。 + onContactAdded: function (msg) {}, + // 当前用户发送的好友请求被拒绝。 + onContactRefuse: function (msg) {}, + // 当前用户发送的好友请求被同意。 + onContactAgreed: function (msg) { + store.initContactsListFromServer() + }, + }) + /* 群组相关监听 */ + EMClient.addEventHandler("GROUPS", { + onGroupEvent: (event) => { + console.log('GROUP EVETN', event); + switch (event.operation) { + // 有新群组创建。群主的其他设备会收到该回调。 + case "create": + break; + // 关闭群组一键禁言。群组所有成员(除操作者外)会收到该回调。 + case "unmuteAllMembers": + break; + // 开启群组一键禁言。群组所有成员(除操作者外)会收到该回调。 + case "muteAllMembers": + break; + // 有成员从群白名单中移出。被移出的成员及群主和群管理员(除操作者外)会收到该回调。 + case "removeAllowlistMember": + break; + // 有成员添加至群白名单。被添加的成员及群主和群管理员(除操作者外)会收到该回调。 + case "addUserToAllowlist": + break; + // 删除群共享文件。群组所有成员会收到该回调。 + case "deleteFile": + break; + // 上传群共享文件。群组所有成员会收到该回调。 + case "uploadFile": + break; + // 删除群公告。群组所有成员会收到该回调。 + case "deleteAnnouncement": + break; + // 更新群公告。群组所有成员会收到该回调。 + case "updateAnnouncement": + break; + // 更新群组信息,如群组名称和群组描述。群组所有成员会收到该回调。 + case "updateInfo": + break; + // 有成员被移出禁言列表。被解除禁言的成员及群主和群管理员(除操作者外)会收到该回调。 + case "unmuteMember": + break; + // 有群组成员被加入禁言列表。被禁言的成员及群主和群管理员(除操作者外)会收到该回调。 + case "muteMember": + break; + // 有管理员被移出管理员列表。群主、被移除的管理员和其他管理员会收到该回调。 + case "removeAdmin": + break; + // 设置管理员。群主、新管理员和其他管理员会收到该回调。 + case "setAdmin": + break; + // 转让群组。新群主会收到该回调。 + case "changeOwner": + break; + // 群组所有者和管理员拉用户进群时,无需用户确认时会触发该回调。被拉进群的用户会收到该回调。 + case "directJoined": + break; + // 群成员主动退出群组。除了退群的成员,其他群成员会收到该回调。 + case "memberAbsence": + break; + // 有用户加入群组。除了新成员,其他群成员会收到该回调。 + case "memberPresence": + break; + // 用户被移出群组。被踢出群组的成员会收到该回调。 + case "removeMember": + break; + // 当前用户的入群邀请被拒绝。邀请人会收到该回调。例如,用户 B 拒绝了用户 A 的入群邀请,用户 A 会收到该回调。 + case "rejectInvite": + break; + // 当前用户的入群邀请被接受。邀请人会收到该回调。例如,用户 B 接受了用户 A 的入群邀请,则用户 A 会收到该回调。 + case "acceptInvite": + break; + // 当前用户收到了入群邀请。受邀用户会收到该回调。例如,用户 B 邀请用户 A 入群,则用户 A 会收到该回调。 + case "inviteToJoin": { + event.chatType = 'groupChat' + event.key = event.id + store.updateNotificationsList({ + ...event + }) + } + break; + // 当前用户的入群申请被拒绝。申请人会收到该回调。例如,用户 B 拒绝用户 A 的入群申请后,用户 A 会收到该回调。 + case "joinPublicGroupDeclined": + break; + // 当前用户的入群申请被接受。申请人会收到该回调。例如,用户 B 接受用户 A 的入群申请后,用户 A 会收到该回调。 + case "acceptRequest": + break; + // 当前用户发送入群申请。群主和群管理员会收到该回调。 + case "requestToJoin": + break; + // 群组被解散。群主解散群组时,所有群成员均会收到该回调。 + case "destroy": + break; + // 设置群成员的自定义属性。群组内其他成员均会收到该回调。 + case "memberAttributesUpdate": + break; + default: + break; + } + } + }) + }, + + onUnload() {}, + +}); \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..4b0ebda --- /dev/null +++ b/app.json @@ -0,0 +1,48 @@ +{ + "pages": [ + "pages/login/index", + "pages/conversation/index", + "pages/contacts/index", + "pages/mine/index", + "pages/chat/index", + "pages/addContacts/index", + "pages/groupList/index", + "pages/blackList/index", + "pages/contactsDetail/index", + "pages/groupDetail/index", + "pages/contactsRemark/index", + "pages/groupMemberList/index", + "pages/editGroupInfos/index", + "pages/createGroup/index", + "pages/notifications/index", + "pages/profileEdit/profilePrview/index", + "pages/profileEdit/nicknameEdit/index", + "pages/groupMemberList/addGroupMember/index", + "pages/groupMemberList/deleteGroupMember/index" + ], + "window": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "EaseIM", + "navigationBarBackgroundColor": "#ffffff" + }, + "tabBar": { + "custom": true, + "color": "#000000", + "selectedColor": "#3cc51f", + "backgroundColor": "#ffffff", + "list": [ + { + "pagePath": "pages/conversation/index" + }, + { + "pagePath": "pages/contacts/index" + }, + { + "pagePath": "pages/mine/index" + } + ] + }, + "componentFramework": "glass-easel", + "sitemapLocation": "sitemap.json", + "lazyCodeLoading": "requiredComponents" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..10f0e6f --- /dev/null +++ b/app.wxss @@ -0,0 +1,26 @@ +/**app.wxss**/ +page { + font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, + Segoe UI, Arial, Roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei', + sans-serif; +} +.text-ellipsis { + /* 限制显示在一行 */ + white-space: nowrap; + /* 隐藏溢出的文本 */ + overflow: hidden; + /* 文本溢出时显示省略号 */ + text-overflow: ellipsis; + /* 可选:设置最大宽度 */ + max-width: 150px; /* 根据实际需要调整宽度 */ +} + +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/constants/eomji.js b/constants/eomji.js new file mode 100644 index 0000000..4047511 --- /dev/null +++ b/constants/eomji.js @@ -0,0 +1,320 @@ +export const emojis = [ + '😀', + '😃', + '😄', + '😁', + '😆', + '😅', + '🤣', + '😂', + '🙂', + '🙃', + '😉', + '😊', + '😇', + '😍', + '🤩', + '😘', + '😗', + '😚', + '😙', + '😋', + '😛', + '😜', + '🤪', + '😝', + '🤑', + '🤗', + '🤭', + '🤫', + '🤔', + '🤐', + '🤨', + '😐', + '😑', + '😶', + '😏', + '😒', + '🙄', + '😬', + '🤥', + '😌', + '😔', + '😪', + '🤤', + '😴', + '😷', + '🤒', + '🤕', + '🤢', + '🤮', + '🤧', + '😵', + '🤯', + '🤠', + '😎', + '🤓', + '🧐', + '😕', + '😟', + '🙁', + '😮', + '😯', + '😲', + '😳', + '😦', + '😧', + '😨', + '😰', + '😥', + '😢', + '😭', + '😱', + '😖', + '😣', + '😞', + '😓', + '😩', + '😫', + '😤', + '😡', + '😠', + '🤬', + '😈', + '👿', + '💀', + '💩', + '🤡', + '👹', + '👺', + '👻', + '👽', + '👾', + '🤖', + '😺', + '😸', + '😹', + '😻', + '😼', + '😽', + '🙀', + '😿', + '😾', + '💋', + '👋', + '🤚', + '🖐', + '✋', + '🖖', + '👌', + '🤞', + '🤟', + '🤘', + '🤙', + '👈', + '👉', + '👆', + '🖕', + '👇', + '👍', + '👎', + '✊', + '👊', + '🤛', + '🤜', + '👏', + '🙌', + '👐', + '🤲', + '🤝', + '🙏', + '💅', + '🤳', + '💪', + '👂', + '👃', + '🧠', + '👀', + '👁', + '👅', + '👄', + '👶', + '🧒', + '👦', + '👧', + '🧑', + '👱', + '👨', + '🧔', + '👱‍', + '👨‍', + '👨‍', + '👩', + '👱‍', + '👩‍', + '👩‍', + '👩‍', + '👩‍', + '🧓', + '👴', + '👵', + '🙍', + '🙅', + '🙆', + '💁', + '🙋', + '🙇', + '🙇‍', + '🙇‍', + '🤦', + '🤷', + '🤷‍', + '🤷‍', + '👨‍⚕️', + '👩‍⚕️', + '👨‍🎓', + '👩‍🎓', + '👨‍🏫', + '👩‍🏫', + '👨‍⚖️', + '👩‍⚖️', + '👨‍🌾', + '👩‍🌾', + '👨‍🍳', + '👩‍🍳', + '👨‍🔧', + '👩‍🔧', + '👨‍🏭', + '👩‍🏭', + '👨‍💼', + '👩‍💼', + '👨‍🔬', + '👩‍🔬', + '👨‍💻', + '👩‍💻', + '👨‍🎤', + '👩‍🎤', + '👨‍🎨', + '👩‍🎨', + '👨‍✈️', + '👩‍✈️', + '👨‍🚀', + '👩‍🚀', + '👨‍🚒', + '👩‍🚒', + '👮', + '👮‍♂️', + '👮‍♀️', + '🕵', + '🕵️‍♂️', + '🕵️‍♀️', + '💂', + '💂‍', + '💂‍', + '👷', + '👷‍', + '👷‍', + '🤴', + '👸', + '👳', + '👳‍', + '👳‍', + '👲', + '🧕', + '🤵', + '👰', + '🤰', + '🤱', + '👼', + '🎅', + '🤶', + '🧙', + '🧚', + '🧛', + '🧜', + '🧝', + '🧞', + '🧟', + '💆', + '💇', + '🚶', + '🏃', + '💃', + '🕺', + '🕴', + '👯', + '🧖', + '🧖‍', + '🧖‍', + '🧘', + '👭', + '👫', + '👬', + '💏', + '👨‍', + '👩‍', + '💑', + '👨‍', + '👩‍', + '👪', + '👨‍👩‍👦', + '👨‍👩‍👧', + '👨‍👩‍👧‍👦', + '👨‍👩‍👦‍👦', + '👨‍👩‍👧‍👧', + '👨‍👨‍👦', + '👨‍👨‍👧', + '👨‍👨‍👧‍👦', + '👩‍👩‍👦', + '👩‍👩‍👧', + '👩‍👩‍👧‍👦', + '👩‍👩‍👦‍👦', + '👩‍👩‍👧‍👧', + '👨‍👦', + '👨‍👦‍👦', + '👨‍👧', + '👨‍👧‍👦', + '👨‍👧‍👧', + '👩‍👦', + '👩‍👦‍👦', + '👩‍👧', + '👩‍👧‍👦', + '👩‍👧‍👧', + '🗣', + '👤', + '👥', + '👣', + '🌂', + '☂', + '👓', + '🕶', + '👔', + '👕', + '👖', + '🧣', + '🧤', + '🧥', + '🧦', + '👗', + '👘', + '👙', + '👚', + '👛', + '👜', + '👝', + '🎒', + '👞', + '👟', + '👠', + '👡', + '👢', + '👑', + '👒', + '🎩', + '🎓', + '🧢', + '⛑', + '💄', + '💍', + '💼' +] diff --git a/constants/index.js b/constants/index.js new file mode 100644 index 0000000..691c32e --- /dev/null +++ b/constants/index.js @@ -0,0 +1 @@ +export * from './eomji' \ No newline at end of file diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js new file mode 100644 index 0000000..3989542 --- /dev/null +++ b/custom-tab-bar/index.js @@ -0,0 +1,50 @@ +import { ComponentWithStore } from 'mobx-miniprogram-bindings'; +import { store } from '../store/index'; +ComponentWithStore({ + /** + * 组件的初始数据 + */ + storeBindings:{ + store: store, + fields: ['notificationsList','totalUnreadCount'], + // actions: ['update'] + }, + data: { + active: 0, + border:false, + tabbarPlaceholder:true, + list: [ + { + text: '会话', + url: '/pages/conversation/index' + }, + { + text: '联系人', + url: '/pages/contacts/index' + }, + { + text:'我的', + url:'/pages/mine/index' + } + ] + }, + + /** + * 组件的方法列表 + */ + methods: { + onTabbarChange(event) { + this.setData({ active: event.detail }); + wx.switchTab({ + url: this.data.list[event.detail].url + }); + }, + init() { + const page = getCurrentPages().pop(); + console.log(page.route) + this.setData({ + active: this.data.list.findIndex(item => item.url === `/${page.route}`) + }); + } + } +}) \ No newline at end of file diff --git a/custom-tab-bar/index.json b/custom-tab-bar/index.json new file mode 100644 index 0000000..21164f6 --- /dev/null +++ b/custom-tab-bar/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-tabbar": "@vant/weapp/tabbar/index", + "van-tabbar-item": "@vant/weapp/tabbar-item/index" + } +} \ No newline at end of file diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml new file mode 100644 index 0000000..fde1802 --- /dev/null +++ b/custom-tab-bar/index.wxml @@ -0,0 +1,18 @@ + + + + + + 会话 + + + + + 联系人 + + + + + 我的 + + \ No newline at end of file diff --git a/src/comps/chat/inputbar/suit/image/image.wxml b/custom-tab-bar/index.wxss similarity index 100% rename from src/comps/chat/inputbar/suit/image/image.wxml rename to custom-tab-bar/index.wxss diff --git a/miniprogram_npm/@vant/weapp/action-sheet/index.d.ts b/miniprogram_npm/@vant/weapp/action-sheet/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/action-sheet/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/action-sheet/index.js b/miniprogram_npm/@vant/weapp/action-sheet/index.js new file mode 100644 index 0000000..8403b68 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/action-sheet/index.js @@ -0,0 +1,78 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var button_1 = require("../mixins/button"); +(0, component_1.VantComponent)({ + classes: ['list-class'], + mixins: [button_1.button], + props: { + show: Boolean, + title: String, + cancelText: String, + description: String, + round: { + type: Boolean, + value: true, + }, + zIndex: { + type: Number, + value: 100, + }, + actions: { + type: Array, + value: [], + }, + overlay: { + type: Boolean, + value: true, + }, + closeOnClickOverlay: { + type: Boolean, + value: true, + }, + closeOnClickAction: { + type: Boolean, + value: true, + }, + safeAreaInsetBottom: { + type: Boolean, + value: true, + }, + rootPortal: { + type: Boolean, + value: false, + }, + }, + methods: { + onSelect: function (event) { + var _this = this; + var index = event.currentTarget.dataset.index; + var _a = this.data, actions = _a.actions, closeOnClickAction = _a.closeOnClickAction, canIUseGetUserProfile = _a.canIUseGetUserProfile; + var item = actions[index]; + if (item) { + this.$emit('select', item); + if (closeOnClickAction) { + this.onClose(); + } + if (item.openType === 'getUserInfo' && canIUseGetUserProfile) { + wx.getUserProfile({ + desc: item.getUserProfileDesc || ' ', + complete: function (userProfile) { + _this.$emit('getuserinfo', userProfile); + }, + }); + } + } + }, + onCancel: function () { + this.$emit('cancel'); + }, + onClose: function () { + this.$emit('close'); + }, + onClickOverlay: function () { + this.$emit('click-overlay'); + this.onClose(); + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/action-sheet/index.json b/miniprogram_npm/@vant/weapp/action-sheet/index.json new file mode 100644 index 0000000..19bf989 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/action-sheet/index.json @@ -0,0 +1,8 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index", + "van-popup": "../popup/index", + "van-loading": "../loading/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/action-sheet/index.wxml b/miniprogram_npm/@vant/weapp/action-sheet/index.wxml new file mode 100644 index 0000000..6311e33 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/action-sheet/index.wxml @@ -0,0 +1,70 @@ + + + + + {{ title }} + + + + {{ description }} + + + + + + + + + + {{ cancelText }} + + + diff --git a/miniprogram_npm/@vant/weapp/action-sheet/index.wxss b/miniprogram_npm/@vant/weapp/action-sheet/index.wxss new file mode 100644 index 0000000..eedd361 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/action-sheet/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-action-sheet{color:var(--action-sheet-item-text-color,#323233);max-height:var(--action-sheet-max-height,90%)!important}.van-action-sheet__cancel,.van-action-sheet__item{background-color:var(--action-sheet-item-background,#fff);font-size:var(--action-sheet-item-font-size,16px);line-height:var(--action-sheet-item-line-height,22px);padding:14px 16px;text-align:center}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5}.van-action-sheet__cancel:after,.van-action-sheet__item:after{border-width:0}.van-action-sheet__cancel{color:var(--action-sheet-cancel-text-color,#646566)}.van-action-sheet__gap{background-color:var(--action-sheet-cancel-padding-color,#f7f8fa);display:block;height:var(--action-sheet-cancel-padding-top,8px)}.van-action-sheet__item--disabled{color:var(--action-sheet-item-disabled-text-color,#c8c9cc)}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__subname{color:var(--action-sheet-subname-color,#969799);font-size:var(--action-sheet-subname-font-size,12px);line-height:var(--action-sheet-subname-line-height,20px);margin-top:var(--padding-xs,8px)}.van-action-sheet__header{font-size:var(--action-sheet-header-font-size,16px);font-weight:var(--font-weight-bold,500);line-height:var(--action-sheet-header-height,48px);text-align:center}.van-action-sheet__description{color:var(--action-sheet-description-color,#969799);font-size:var(--action-sheet-description-font-size,14px);line-height:var(--action-sheet-description-line-height,20px);padding:20px var(--padding-md,16px);text-align:center}.van-action-sheet__close{color:var(--action-sheet-close-icon-color,#c8c9cc);font-size:var(--action-sheet-close-icon-size,22px)!important;line-height:inherit!important;padding:var(--action-sheet-close-icon-padding,0 16px);position:absolute!important;right:0;top:0}.van-action-sheet__loading{display:flex!important} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/button/index.d.ts b/miniprogram_npm/@vant/weapp/button/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/button/index.js b/miniprogram_npm/@vant/weapp/button/index.js new file mode 100644 index 0000000..984135c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var button_1 = require("../mixins/button"); +var version_1 = require("../common/version"); +var mixins = [button_1.button]; +if ((0, version_1.canIUseFormFieldButton)()) { + mixins.push('wx://form-field-button'); +} +(0, component_1.VantComponent)({ + mixins: mixins, + classes: ['hover-class', 'loading-class'], + data: { + baseStyle: '', + }, + props: { + formType: String, + icon: String, + classPrefix: { + type: String, + value: 'van-icon', + }, + plain: Boolean, + block: Boolean, + round: Boolean, + square: Boolean, + loading: Boolean, + hairline: Boolean, + disabled: Boolean, + loadingText: String, + customStyle: String, + loadingType: { + type: String, + value: 'circular', + }, + type: { + type: String, + value: 'default', + }, + dataset: null, + size: { + type: String, + value: 'normal', + }, + loadingSize: { + type: String, + value: '20px', + }, + color: String, + }, + methods: { + onClick: function (event) { + var _this = this; + this.$emit('click', event); + var _a = this.data, canIUseGetUserProfile = _a.canIUseGetUserProfile, openType = _a.openType, getUserProfileDesc = _a.getUserProfileDesc, lang = _a.lang; + if (openType === 'getUserInfo' && canIUseGetUserProfile) { + wx.getUserProfile({ + desc: getUserProfileDesc || ' ', + lang: lang || 'en', + complete: function (userProfile) { + _this.$emit('getuserinfo', userProfile); + }, + }); + } + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/button/index.json b/miniprogram_npm/@vant/weapp/button/index.json new file mode 100644 index 0000000..e00a588 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index", + "van-loading": "../loading/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/button/index.wxml b/miniprogram_npm/@vant/weapp/button/index.wxml new file mode 100644 index 0000000..e7f60f1 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.wxml @@ -0,0 +1,56 @@ + + + + diff --git a/miniprogram_npm/@vant/weapp/button/index.wxs b/miniprogram_npm/@vant/weapp/button/index.wxs new file mode 100644 index 0000000..8b649fe --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.wxs @@ -0,0 +1,39 @@ +/* eslint-disable */ +var style = require('../wxs/style.wxs'); + +function rootStyle(data) { + if (!data.color) { + return data.customStyle; + } + + var properties = { + color: data.plain ? data.color : '#fff', + background: data.plain ? null : data.color, + }; + + // hide border when color is linear-gradient + if (data.color.indexOf('gradient') !== -1) { + properties.border = 0; + } else { + properties['border-color'] = data.color; + } + + return style([properties, data.customStyle]); +} + +function loadingColor(data) { + if (data.plain) { + return data.color ? data.color : '#c9c9c9'; + } + + if (data.type === 'default') { + return '#c9c9c9'; + } + + return '#fff'; +} + +module.exports = { + rootStyle: rootStyle, + loadingColor: loadingColor, +}; diff --git a/miniprogram_npm/@vant/weapp/button/index.wxss b/miniprogram_npm/@vant/weapp/button/index.wxss new file mode 100644 index 0000000..bd8bb5a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/button/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-button{-webkit-text-size-adjust:100%;align-items:center;-webkit-appearance:none;border-radius:var(--button-border-radius,2px);box-sizing:border-box;display:inline-flex;font-size:var(--button-default-font-size,16px);height:var(--button-default-height,44px);justify-content:center;line-height:var(--button-line-height,20px);padding:0;position:relative;text-align:center;transition:opacity .2s;vertical-align:middle}.van-button:before{background-color:#000;border:inherit;border-color:#000;border-radius:inherit;content:" ";height:100%;left:50%;opacity:0;position:absolute;top:50%;transform:translate(-50%,-50%);width:100%}.van-button:after{border-width:0}.van-button--active:before{opacity:.15}.van-button--unclickable:after{display:none}.van-button--default{background:var(--button-default-background-color,#fff);border:var(--button-border-width,1px) solid var(--button-default-border-color,#ebedf0);color:var(--button-default-color,#323233)}.van-button--primary{background:var(--button-primary-background-color,#07c160);border:var(--button-border-width,1px) solid var(--button-primary-border-color,#07c160);color:var(--button-primary-color,#fff)}.van-button--info{background:var(--button-info-background-color,#1989fa);border:var(--button-border-width,1px) solid var(--button-info-border-color,#1989fa);color:var(--button-info-color,#fff)}.van-button--danger{background:var(--button-danger-background-color,#ee0a24);border:var(--button-border-width,1px) solid var(--button-danger-border-color,#ee0a24);color:var(--button-danger-color,#fff)}.van-button--warning{background:var(--button-warning-background-color,#ff976a);border:var(--button-border-width,1px) solid var(--button-warning-border-color,#ff976a);color:var(--button-warning-color,#fff)}.van-button--plain{background:var(--button-plain-background-color,#fff)}.van-button--plain.van-button--primary{color:var(--button-primary-background-color,#07c160)}.van-button--plain.van-button--info{color:var(--button-info-background-color,#1989fa)}.van-button--plain.van-button--danger{color:var(--button-danger-background-color,#ee0a24)}.van-button--plain.van-button--warning{color:var(--button-warning-background-color,#ff976a)}.van-button--large{height:var(--button-large-height,50px);width:100%}.van-button--normal{font-size:var(--button-normal-font-size,14px);padding:0 15px}.van-button--small{font-size:var(--button-small-font-size,12px);height:var(--button-small-height,30px);min-width:var(--button-small-min-width,60px);padding:0 var(--padding-xs,8px)}.van-button--mini{display:inline-block;font-size:var(--button-mini-font-size,10px);height:var(--button-mini-height,22px);min-width:var(--button-mini-min-width,50px)}.van-button--mini+.van-button--mini{margin-left:5px}.van-button--block{display:flex;width:100%}.van-button--round{border-radius:var(--button-round-border-radius,999px)}.van-button--square{border-radius:0}.van-button--disabled{opacity:var(--button-disabled-opacity,.5)}.van-button__text{display:inline}.van-button__icon+.van-button__text:not(:empty),.van-button__loading-text{margin-left:4px}.van-button__icon{line-height:inherit!important;min-width:1em;vertical-align:top}.van-button--hairline{border-width:0;padding-top:1px}.van-button--hairline:after{border-color:inherit;border-radius:calc(var(--button-border-radius, 2px)*2);border-width:1px}.van-button--hairline.van-button--round:after{border-radius:var(--button-round-border-radius,999px)}.van-button--hairline.van-button--square:after{border-radius:0} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/cell-group/index.d.ts b/miniprogram_npm/@vant/weapp/cell-group/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/cell-group/index.js b/miniprogram_npm/@vant/weapp/cell-group/index.js new file mode 100644 index 0000000..34a93a6 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell-group/index.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +(0, component_1.VantComponent)({ + props: { + title: String, + border: { + type: Boolean, + value: true, + }, + inset: Boolean, + }, +}); diff --git a/src/comps/chat/inputbar/suit/ptopcall/ptopcall.json b/miniprogram_npm/@vant/weapp/cell-group/index.json similarity index 100% rename from src/comps/chat/inputbar/suit/ptopcall/ptopcall.json rename to miniprogram_npm/@vant/weapp/cell-group/index.json diff --git a/miniprogram_npm/@vant/weapp/cell-group/index.wxml b/miniprogram_npm/@vant/weapp/cell-group/index.wxml new file mode 100644 index 0000000..311e064 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell-group/index.wxml @@ -0,0 +1,11 @@ + + + + {{ title }} + + + + diff --git a/miniprogram_npm/@vant/weapp/cell-group/index.wxss b/miniprogram_npm/@vant/weapp/cell-group/index.wxss new file mode 100644 index 0000000..08b252f --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell-group/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-cell-group--inset{border-radius:var(--cell-group-inset-border-radius,8px);margin:var(--cell-group-inset-padding,0 16px);overflow:hidden}.van-cell-group__title{color:var(--cell-group-title-color,#969799);font-size:var(--cell-group-title-font-size,14px);line-height:var(--cell-group-title-line-height,16px);padding:var(--cell-group-title-padding,16px 16px 8px)}.van-cell-group__title--inset{padding:var(--cell-group-inset-title-padding,16px 16px 8px 32px)} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/cell/index.d.ts b/miniprogram_npm/@vant/weapp/cell/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/cell/index.js b/miniprogram_npm/@vant/weapp/cell/index.js new file mode 100644 index 0000000..80f3039 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var link_1 = require("../mixins/link"); +var component_1 = require("../common/component"); +(0, component_1.VantComponent)({ + classes: [ + 'title-class', + 'label-class', + 'value-class', + 'right-icon-class', + 'hover-class', + ], + mixins: [link_1.link], + props: { + title: null, + value: null, + icon: String, + size: String, + label: String, + center: Boolean, + isLink: Boolean, + required: Boolean, + clickable: Boolean, + titleWidth: String, + customStyle: String, + arrowDirection: String, + useLabelSlot: Boolean, + border: { + type: Boolean, + value: true, + }, + titleStyle: String, + }, + methods: { + onClick: function (event) { + this.$emit('click', event.detail); + this.jumpLink(); + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/cell/index.json b/miniprogram_npm/@vant/weapp/cell/index.json new file mode 100644 index 0000000..0a336c0 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/cell/index.wxml b/miniprogram_npm/@vant/weapp/cell/index.wxml new file mode 100644 index 0000000..8387c3c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.wxml @@ -0,0 +1,47 @@ + + + + + + + + + + {{ title }} + + + + + {{ label }} + + + + + {{ value }} + + + + + + + + diff --git a/miniprogram_npm/@vant/weapp/cell/index.wxs b/miniprogram_npm/@vant/weapp/cell/index.wxs new file mode 100644 index 0000000..e3500c4 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.wxs @@ -0,0 +1,17 @@ +/* eslint-disable */ +var style = require('../wxs/style.wxs'); +var addUnit = require('../wxs/add-unit.wxs'); + +function titleStyle(data) { + return style([ + { + 'max-width': addUnit(data.titleWidth), + 'min-width': addUnit(data.titleWidth), + }, + data.titleStyle, + ]); +} + +module.exports = { + titleStyle: titleStyle, +}; diff --git a/miniprogram_npm/@vant/weapp/cell/index.wxss b/miniprogram_npm/@vant/weapp/cell/index.wxss new file mode 100644 index 0000000..1802f8e --- /dev/null +++ b/miniprogram_npm/@vant/weapp/cell/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-cell{background-color:var(--cell-background-color,#fff);box-sizing:border-box;color:var(--cell-text-color,#323233);display:flex;font-size:var(--cell-font-size,14px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,10px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.van-cell:after{border-bottom:1px solid #ebedf0;bottom:0;box-sizing:border-box;content:" ";left:16px;pointer-events:none;position:absolute;right:16px;transform:scaleY(.5);transform-origin:center}.van-cell--borderless:after{display:none}.van-cell-group{background-color:var(--cell-background-color,#fff)}.van-cell__label{color:var(--cell-label-color,#969799);font-size:var(--cell-label-font-size,12px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.van-cell__value{color:var(--cell-value-color,#969799);overflow:hidden;text-align:right;vertical-align:middle}.van-cell__title,.van-cell__value{flex:1}.van-cell__title:empty,.van-cell__value:empty{display:none}.van-cell__left-icon-wrap,.van-cell__right-icon-wrap{align-items:center;display:flex;font-size:var(--cell-icon-size,16px);height:var(--cell-line-height,24px)}.van-cell__left-icon-wrap{margin-right:var(--padding-base,4px)}.van-cell__right-icon-wrap{color:var(--cell-right-icon-color,#969799);margin-left:var(--padding-base,4px)}.van-cell__left-icon{vertical-align:middle}.van-cell__left-icon,.van-cell__right-icon{line-height:var(--cell-line-height,24px)}.van-cell--clickable.van-cell--hover{background-color:var(--cell-active-color,#f2f3f5)}.van-cell--required{overflow:visible}.van-cell--required:before{color:var(--cell-required-color,#ee0a24);content:"*";font-size:var(--cell-font-size,14px);left:var(--padding-xs,8px);position:absolute}.van-cell--center{align-items:center}.van-cell--large{padding-bottom:var(--cell-large-vertical-padding,12px);padding-top:var(--cell-large-vertical-padding,12px)}.van-cell--large .van-cell__title{font-size:var(--cell-large-title-font-size,16px)}.van-cell--large .van-cell__value{font-size:var(--cell-large-value-font-size,16px)}.van-cell--large .van-cell__label{font-size:var(--cell-large-label-font-size,14px)} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/checkbox-group/index.d.ts b/miniprogram_npm/@vant/weapp/checkbox-group/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox-group/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/checkbox-group/index.js b/miniprogram_npm/@vant/weapp/checkbox-group/index.js new file mode 100644 index 0000000..80c93a1 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox-group/index.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var relation_1 = require("../common/relation"); +var component_1 = require("../common/component"); +(0, component_1.VantComponent)({ + field: true, + relation: (0, relation_1.useChildren)('checkbox', function (target) { + this.updateChild(target); + }), + props: { + max: Number, + value: { + type: Array, + observer: 'updateChildren', + }, + disabled: { + type: Boolean, + observer: 'updateChildren', + }, + direction: { + type: String, + value: 'vertical', + }, + }, + methods: { + updateChildren: function () { + var _this = this; + this.children.forEach(function (child) { return _this.updateChild(child); }); + }, + updateChild: function (child) { + var _a = this.data, value = _a.value, disabled = _a.disabled, direction = _a.direction; + child.setData({ + value: value.indexOf(child.data.name) !== -1, + parentDisabled: disabled, + direction: direction, + }); + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/checkbox-group/index.json b/miniprogram_npm/@vant/weapp/checkbox-group/index.json new file mode 100644 index 0000000..467ce29 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox-group/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/miniprogram_npm/@vant/weapp/checkbox-group/index.wxml b/miniprogram_npm/@vant/weapp/checkbox-group/index.wxml new file mode 100644 index 0000000..638bf9d --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox-group/index.wxml @@ -0,0 +1,5 @@ + + + + + diff --git a/miniprogram_npm/@vant/weapp/checkbox-group/index.wxss b/miniprogram_npm/@vant/weapp/checkbox-group/index.wxss new file mode 100644 index 0000000..c5666d7 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox-group/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-checkbox-group--horizontal{display:flex;flex-wrap:wrap} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.d.ts b/miniprogram_npm/@vant/weapp/checkbox/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.js b/miniprogram_npm/@vant/weapp/checkbox/index.js new file mode 100644 index 0000000..6247365 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.js @@ -0,0 +1,79 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var relation_1 = require("../common/relation"); +var component_1 = require("../common/component"); +function emit(target, value) { + target.$emit('input', value); + target.$emit('change', value); +} +(0, component_1.VantComponent)({ + field: true, + relation: (0, relation_1.useParent)('checkbox-group'), + classes: ['icon-class', 'label-class'], + props: { + value: Boolean, + disabled: Boolean, + useIconSlot: Boolean, + checkedColor: String, + labelPosition: { + type: String, + value: 'right', + }, + labelDisabled: Boolean, + shape: { + type: String, + value: 'round', + }, + iconSize: { + type: null, + value: 20, + }, + }, + data: { + parentDisabled: false, + direction: 'vertical', + }, + methods: { + emitChange: function (value) { + if (this.parent) { + this.setParentValue(this.parent, value); + } + else { + emit(this, value); + } + }, + toggle: function () { + var _a = this.data, parentDisabled = _a.parentDisabled, disabled = _a.disabled, value = _a.value; + if (!disabled && !parentDisabled) { + this.emitChange(!value); + } + }, + onClickLabel: function () { + var _a = this.data, labelDisabled = _a.labelDisabled, parentDisabled = _a.parentDisabled, disabled = _a.disabled, value = _a.value; + if (!disabled && !labelDisabled && !parentDisabled) { + this.emitChange(!value); + } + }, + setParentValue: function (parent, value) { + var parentValue = parent.data.value.slice(); + var name = this.data.name; + var max = parent.data.max; + if (value) { + if (max && parentValue.length >= max) { + return; + } + if (parentValue.indexOf(name) === -1) { + parentValue.push(name); + emit(parent, parentValue); + } + } + else { + var index = parentValue.indexOf(name); + if (index !== -1) { + parentValue.splice(index, 1); + emit(parent, parentValue); + } + } + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.json b/miniprogram_npm/@vant/weapp/checkbox/index.json new file mode 100644 index 0000000..0a336c0 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.wxml b/miniprogram_npm/@vant/weapp/checkbox/index.wxml new file mode 100644 index 0000000..39a7bb0 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.wxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.wxs b/miniprogram_npm/@vant/weapp/checkbox/index.wxs new file mode 100644 index 0000000..eb9c772 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.wxs @@ -0,0 +1,20 @@ +/* eslint-disable */ +var style = require('../wxs/style.wxs'); +var addUnit = require('../wxs/add-unit.wxs'); + +function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) { + var styles = { + 'font-size': addUnit(iconSize), + }; + + if (checkedColor && value && !disabled && !parentDisabled) { + styles['border-color'] = checkedColor; + styles['background-color'] = checkedColor; + } + + return style(styles); +} + +module.exports = { + iconStyle: iconStyle, +}; diff --git a/miniprogram_npm/@vant/weapp/checkbox/index.wxss b/miniprogram_npm/@vant/weapp/checkbox/index.wxss new file mode 100644 index 0000000..da2272a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/checkbox/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-checkbox{align-items:center;display:flex;overflow:hidden;-webkit-user-select:none;user-select:none}.van-checkbox--horizontal{margin-right:12px}.van-checkbox__icon-wrap,.van-checkbox__label{line-height:var(--checkbox-size,20px)}.van-checkbox__icon-wrap{flex:none}.van-checkbox__icon{align-items:center;border:1px solid var(--checkbox-border-color,#c8c9cc);box-sizing:border-box;color:transparent;display:flex;font-size:var(--checkbox-size,20px);height:1em;justify-content:center;text-align:center;transition-duration:var(--checkbox-transition-duration,.2s);transition-property:color,border-color,background-color;width:1em}.van-checkbox__icon--round{border-radius:100%}.van-checkbox__icon--checked{background-color:var(--checkbox-checked-icon-color,#1989fa);border-color:var(--checkbox-checked-icon-color,#1989fa);color:#fff}.van-checkbox__icon--disabled{background-color:var(--checkbox-disabled-background-color,#ebedf0);border-color:var(--checkbox-disabled-icon-color,#c8c9cc)}.van-checkbox__icon--disabled.van-checkbox__icon--checked{color:var(--checkbox-disabled-icon-color,#c8c9cc)}.van-checkbox__label{word-wrap:break-word;color:var(--checkbox-label-color,#323233);padding-left:var(--checkbox-label-margin,10px)}.van-checkbox__label--left{float:left;margin:0 var(--checkbox-label-margin,10px) 0 0}.van-checkbox__label--disabled{color:var(--checkbox-disabled-label-color,#c8c9cc)}.van-checkbox__label:empty{margin:0} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/common/color.d.ts b/miniprogram_npm/@vant/weapp/common/color.d.ts new file mode 100644 index 0000000..386f307 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/color.d.ts @@ -0,0 +1,7 @@ +export declare const RED = "#ee0a24"; +export declare const BLUE = "#1989fa"; +export declare const WHITE = "#fff"; +export declare const GREEN = "#07c160"; +export declare const ORANGE = "#ff976a"; +export declare const GRAY = "#323233"; +export declare const GRAY_DARK = "#969799"; diff --git a/miniprogram_npm/@vant/weapp/common/color.js b/miniprogram_npm/@vant/weapp/common/color.js new file mode 100644 index 0000000..008a45a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/color.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.GRAY_DARK = exports.GRAY = exports.ORANGE = exports.GREEN = exports.WHITE = exports.BLUE = exports.RED = void 0; +exports.RED = '#ee0a24'; +exports.BLUE = '#1989fa'; +exports.WHITE = '#fff'; +exports.GREEN = '#07c160'; +exports.ORANGE = '#ff976a'; +exports.GRAY = '#323233'; +exports.GRAY_DARK = '#969799'; diff --git a/miniprogram_npm/@vant/weapp/common/component.d.ts b/miniprogram_npm/@vant/weapp/common/component.d.ts new file mode 100644 index 0000000..1d0fd27 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/component.d.ts @@ -0,0 +1,4 @@ +/// +import { VantComponentOptions } from 'definitions/index'; +declare function VantComponent(vantOptions: VantComponentOptions): void; +export { VantComponent }; diff --git a/miniprogram_npm/@vant/weapp/common/component.js b/miniprogram_npm/@vant/weapp/common/component.js new file mode 100644 index 0000000..66da00e --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/component.js @@ -0,0 +1,49 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VantComponent = void 0; +var basic_1 = require("../mixins/basic"); +function mapKeys(source, target, map) { + Object.keys(map).forEach(function (key) { + if (source[key]) { + target[map[key]] = source[key]; + } + }); +} +function VantComponent(vantOptions) { + var options = {}; + mapKeys(vantOptions, options, { + data: 'data', + props: 'properties', + watch: 'observers', + mixins: 'behaviors', + methods: 'methods', + beforeCreate: 'created', + created: 'attached', + mounted: 'ready', + destroyed: 'detached', + classes: 'externalClasses', + }); + // add default externalClasses + options.externalClasses = options.externalClasses || []; + options.externalClasses.push('custom-class'); + // add default behaviors + options.behaviors = options.behaviors || []; + options.behaviors.push(basic_1.basic); + // add relations + var relation = vantOptions.relation; + if (relation) { + options.relations = relation.relations; + options.behaviors.push(relation.mixin); + } + // map field to form-field behavior + if (vantOptions.field) { + options.behaviors.push('wx://form-field'); + } + // add default options + options.options = { + multipleSlots: true, + addGlobalClass: true, + }; + Component(options); +} +exports.VantComponent = VantComponent; diff --git a/miniprogram_npm/@vant/weapp/common/index.wxss b/miniprogram_npm/@vant/weapp/common/index.wxss new file mode 100644 index 0000000..a73bb7a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/index.wxss @@ -0,0 +1 @@ +.van-ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.van-multi-ellipsis--l2{-webkit-line-clamp:2}.van-multi-ellipsis--l2,.van-multi-ellipsis--l3{-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden;text-overflow:ellipsis}.van-multi-ellipsis--l3{-webkit-line-clamp:3}.van-clearfix:after{clear:both;content:"";display:table}.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom:after,.van-hairline--left:after,.van-hairline--right:after,.van-hairline--surround:after,.van-hairline--top-bottom:after,.van-hairline--top:after,.van-hairline:after{border:0 solid #ebedf0;bottom:-50%;box-sizing:border-box;content:" ";left:-50%;pointer-events:none;position:absolute;right:-50%;top:-50%;transform:scale(.5);transform-origin:center}.van-hairline--top:after{border-top-width:1px}.van-hairline--left:after{border-left-width:1px}.van-hairline--right:after{border-right-width:1px}.van-hairline--bottom:after{border-bottom-width:1px}.van-hairline--top-bottom:after{border-width:1px 0}.van-hairline--surround:after{border-width:1px} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/common/relation.d.ts b/miniprogram_npm/@vant/weapp/common/relation.d.ts new file mode 100644 index 0000000..10193fa --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/relation.d.ts @@ -0,0 +1,15 @@ +/// +type TrivialInstance = WechatMiniprogram.Component.TrivialInstance; +export declare function useParent(name: string, onEffect?: (this: TrivialInstance) => void): { + relations: { + [x: string]: WechatMiniprogram.Component.RelationOption; + }; + mixin: string; +}; +export declare function useChildren(name: string, onEffect?: (this: TrivialInstance, target: TrivialInstance) => void): { + relations: { + [x: string]: WechatMiniprogram.Component.RelationOption; + }; + mixin: string; +}; +export {}; diff --git a/miniprogram_npm/@vant/weapp/common/relation.js b/miniprogram_npm/@vant/weapp/common/relation.js new file mode 100644 index 0000000..008256c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/relation.js @@ -0,0 +1,65 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.useChildren = exports.useParent = void 0; +function useParent(name, onEffect) { + var _a; + var path = "../".concat(name, "/index"); + return { + relations: (_a = {}, + _a[path] = { + type: 'ancestor', + linked: function () { + onEffect && onEffect.call(this); + }, + linkChanged: function () { + onEffect && onEffect.call(this); + }, + unlinked: function () { + onEffect && onEffect.call(this); + }, + }, + _a), + mixin: Behavior({ + created: function () { + var _this = this; + Object.defineProperty(this, 'parent', { + get: function () { return _this.getRelationNodes(path)[0]; }, + }); + Object.defineProperty(this, 'index', { + // @ts-ignore + get: function () { var _a, _b; return (_b = (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.indexOf(_this); }, + }); + }, + }), + }; +} +exports.useParent = useParent; +function useChildren(name, onEffect) { + var _a; + var path = "../".concat(name, "/index"); + return { + relations: (_a = {}, + _a[path] = { + type: 'descendant', + linked: function (target) { + onEffect && onEffect.call(this, target); + }, + linkChanged: function (target) { + onEffect && onEffect.call(this, target); + }, + unlinked: function (target) { + onEffect && onEffect.call(this, target); + }, + }, + _a), + mixin: Behavior({ + created: function () { + var _this = this; + Object.defineProperty(this, 'children', { + get: function () { return _this.getRelationNodes(path) || []; }, + }); + }, + }), + }; +} +exports.useChildren = useChildren; diff --git a/miniprogram_npm/@vant/weapp/common/style/clearfix.wxss b/miniprogram_npm/@vant/weapp/common/style/clearfix.wxss new file mode 100644 index 0000000..442246f --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/style/clearfix.wxss @@ -0,0 +1 @@ +.van-clearfix:after{clear:both;content:"";display:table} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/common/style/ellipsis.wxss b/miniprogram_npm/@vant/weapp/common/style/ellipsis.wxss new file mode 100644 index 0000000..ee701df --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/style/ellipsis.wxss @@ -0,0 +1 @@ +.van-ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.van-multi-ellipsis--l2{-webkit-line-clamp:2}.van-multi-ellipsis--l2,.van-multi-ellipsis--l3{-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden;text-overflow:ellipsis}.van-multi-ellipsis--l3{-webkit-line-clamp:3} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/common/style/hairline.wxss b/miniprogram_npm/@vant/weapp/common/style/hairline.wxss new file mode 100644 index 0000000..f7c6260 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/style/hairline.wxss @@ -0,0 +1 @@ +.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom:after,.van-hairline--left:after,.van-hairline--right:after,.van-hairline--surround:after,.van-hairline--top-bottom:after,.van-hairline--top:after,.van-hairline:after{border:0 solid #ebedf0;bottom:-50%;box-sizing:border-box;content:" ";left:-50%;pointer-events:none;position:absolute;right:-50%;top:-50%;transform:scale(.5);transform-origin:center}.van-hairline--top:after{border-top-width:1px}.van-hairline--left:after{border-left-width:1px}.van-hairline--right:after{border-right-width:1px}.van-hairline--bottom:after{border-bottom-width:1px}.van-hairline--top-bottom:after{border-width:1px 0}.van-hairline--surround:after{border-width:1px} \ No newline at end of file diff --git a/src/comps/chat/inputbar/suit/location/location.wxml b/miniprogram_npm/@vant/weapp/common/style/mixins/clearfix.wxss similarity index 100% rename from src/comps/chat/inputbar/suit/location/location.wxml rename to miniprogram_npm/@vant/weapp/common/style/mixins/clearfix.wxss diff --git a/src/comps/chat/inputbar/suit/video/video.wxml b/miniprogram_npm/@vant/weapp/common/style/mixins/ellipsis.wxss similarity index 100% rename from src/comps/chat/inputbar/suit/video/video.wxml rename to miniprogram_npm/@vant/weapp/common/style/mixins/ellipsis.wxss diff --git a/miniprogram_npm/@vant/weapp/common/style/mixins/hairline.wxss b/miniprogram_npm/@vant/weapp/common/style/mixins/hairline.wxss new file mode 100644 index 0000000..e69de29 diff --git a/miniprogram_npm/@vant/weapp/common/style/var.wxss b/miniprogram_npm/@vant/weapp/common/style/var.wxss new file mode 100644 index 0000000..e69de29 diff --git a/miniprogram_npm/@vant/weapp/common/utils.d.ts b/miniprogram_npm/@vant/weapp/common/utils.d.ts new file mode 100644 index 0000000..a77d8c6 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/utils.d.ts @@ -0,0 +1,21 @@ +/// +/// +/// +/// +/// +export { isDef } from './validator'; +export { getSystemInfoSync } from './version'; +export declare function range(num: number, min: number, max: number): number; +export declare function nextTick(cb: (...args: any[]) => void): void; +export declare function addUnit(value?: string | number): string | undefined; +export declare function requestAnimationFrame(cb: () => void): NodeJS.Timeout; +export declare function pickExclude(obj: unknown, keys: string[]): {}; +export declare function getRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise; +export declare function getAllRect(context: WechatMiniprogram.Component.TrivialInstance, selector: string): Promise; +export declare function groupSetData(context: WechatMiniprogram.Component.TrivialInstance, cb: () => void): void; +export declare function toPromise(promiseLike: Promise | unknown): Promise; +export declare function addNumber(num1: any, num2: any): number; +export declare const clamp: (num: any, min: any, max: any) => number; +export declare function getCurrentPage(): T & WechatMiniprogram.OptionalInterface & WechatMiniprogram.Page.InstanceProperties & WechatMiniprogram.Page.InstanceMethods & WechatMiniprogram.Page.Data & WechatMiniprogram.IAnyObject; +export declare const isPC: boolean; +export declare const isWxWork: boolean; diff --git a/miniprogram_npm/@vant/weapp/common/utils.js b/miniprogram_npm/@vant/weapp/common/utils.js new file mode 100644 index 0000000..1727628 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/utils.js @@ -0,0 +1,109 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isWxWork = exports.isPC = exports.getCurrentPage = exports.clamp = exports.addNumber = exports.toPromise = exports.groupSetData = exports.getAllRect = exports.getRect = exports.pickExclude = exports.requestAnimationFrame = exports.addUnit = exports.nextTick = exports.range = exports.getSystemInfoSync = exports.isDef = void 0; +var validator_1 = require("./validator"); +var version_1 = require("./version"); +var validator_2 = require("./validator"); +Object.defineProperty(exports, "isDef", { enumerable: true, get: function () { return validator_2.isDef; } }); +var version_2 = require("./version"); +Object.defineProperty(exports, "getSystemInfoSync", { enumerable: true, get: function () { return version_2.getSystemInfoSync; } }); +function range(num, min, max) { + return Math.min(Math.max(num, min), max); +} +exports.range = range; +function nextTick(cb) { + if ((0, version_1.canIUseNextTick)()) { + wx.nextTick(cb); + } + else { + setTimeout(function () { + cb(); + }, 1000 / 30); + } +} +exports.nextTick = nextTick; +function addUnit(value) { + if (!(0, validator_1.isDef)(value)) { + return undefined; + } + value = String(value); + return (0, validator_1.isNumber)(value) ? "".concat(value, "px") : value; +} +exports.addUnit = addUnit; +function requestAnimationFrame(cb) { + return setTimeout(function () { + cb(); + }, 1000 / 30); +} +exports.requestAnimationFrame = requestAnimationFrame; +function pickExclude(obj, keys) { + if (!(0, validator_1.isPlainObject)(obj)) { + return {}; + } + return Object.keys(obj).reduce(function (prev, key) { + if (!keys.includes(key)) { + prev[key] = obj[key]; + } + return prev; + }, {}); +} +exports.pickExclude = pickExclude; +function getRect(context, selector) { + return new Promise(function (resolve) { + wx.createSelectorQuery() + .in(context) + .select(selector) + .boundingClientRect() + .exec(function (rect) { + if (rect === void 0) { rect = []; } + return resolve(rect[0]); + }); + }); +} +exports.getRect = getRect; +function getAllRect(context, selector) { + return new Promise(function (resolve) { + wx.createSelectorQuery() + .in(context) + .selectAll(selector) + .boundingClientRect() + .exec(function (rect) { + if (rect === void 0) { rect = []; } + return resolve(rect[0]); + }); + }); +} +exports.getAllRect = getAllRect; +function groupSetData(context, cb) { + if ((0, version_1.canIUseGroupSetData)()) { + context.groupSetData(cb); + } + else { + cb(); + } +} +exports.groupSetData = groupSetData; +function toPromise(promiseLike) { + if ((0, validator_1.isPromise)(promiseLike)) { + return promiseLike; + } + return Promise.resolve(promiseLike); +} +exports.toPromise = toPromise; +// 浮点数精度处理 +function addNumber(num1, num2) { + var cardinal = Math.pow(10, 10); + return Math.round((num1 + num2) * cardinal) / cardinal; +} +exports.addNumber = addNumber; +// 限制value在[min, max]之间 +var clamp = function (num, min, max) { return Math.min(Math.max(num, min), max); }; +exports.clamp = clamp; +function getCurrentPage() { + var pages = getCurrentPages(); + return pages[pages.length - 1]; +} +exports.getCurrentPage = getCurrentPage; +exports.isPC = ['mac', 'windows'].includes((0, version_1.getSystemInfoSync)().platform); +// 是否企业微信 +exports.isWxWork = (0, version_1.getSystemInfoSync)().environment === 'wxwork'; diff --git a/miniprogram_npm/@vant/weapp/common/validator.d.ts b/miniprogram_npm/@vant/weapp/common/validator.d.ts new file mode 100644 index 0000000..152894a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/validator.d.ts @@ -0,0 +1,9 @@ +export declare function isFunction(val: unknown): val is Function; +export declare function isPlainObject(val: unknown): val is Record; +export declare function isPromise(val: unknown): val is Promise; +export declare function isDef(value: unknown): boolean; +export declare function isObj(x: unknown): x is Record; +export declare function isNumber(value: string): boolean; +export declare function isBoolean(value: unknown): value is boolean; +export declare function isImageUrl(url: string): boolean; +export declare function isVideoUrl(url: string): boolean; diff --git a/miniprogram_npm/@vant/weapp/common/validator.js b/miniprogram_npm/@vant/weapp/common/validator.js new file mode 100644 index 0000000..169e796 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/validator.js @@ -0,0 +1,43 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isVideoUrl = exports.isImageUrl = exports.isBoolean = exports.isNumber = exports.isObj = exports.isDef = exports.isPromise = exports.isPlainObject = exports.isFunction = void 0; +// eslint-disable-next-line @typescript-eslint/ban-types +function isFunction(val) { + return typeof val === 'function'; +} +exports.isFunction = isFunction; +function isPlainObject(val) { + return val !== null && typeof val === 'object' && !Array.isArray(val); +} +exports.isPlainObject = isPlainObject; +function isPromise(val) { + return isPlainObject(val) && isFunction(val.then) && isFunction(val.catch); +} +exports.isPromise = isPromise; +function isDef(value) { + return value !== undefined && value !== null; +} +exports.isDef = isDef; +function isObj(x) { + var type = typeof x; + return x !== null && (type === 'object' || type === 'function'); +} +exports.isObj = isObj; +function isNumber(value) { + return /^\d+(\.\d+)?$/.test(value); +} +exports.isNumber = isNumber; +function isBoolean(value) { + return typeof value === 'boolean'; +} +exports.isBoolean = isBoolean; +var IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i; +var VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i; +function isImageUrl(url) { + return IMAGE_REGEXP.test(url); +} +exports.isImageUrl = isImageUrl; +function isVideoUrl(url) { + return VIDEO_REGEXP.test(url); +} +exports.isVideoUrl = isVideoUrl; diff --git a/miniprogram_npm/@vant/weapp/common/version.d.ts b/miniprogram_npm/@vant/weapp/common/version.d.ts new file mode 100644 index 0000000..3393221 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/version.d.ts @@ -0,0 +1,15 @@ +/// +interface WxWorkSystemInfo extends WechatMiniprogram.SystemInfo { + environment?: 'wxwork'; +} +interface SystemInfo extends WxWorkSystemInfo, WechatMiniprogram.SystemInfo { +} +export declare function getSystemInfoSync(): SystemInfo; +export declare function canIUseModel(): boolean; +export declare function canIUseFormFieldButton(): boolean; +export declare function canIUseAnimate(): boolean; +export declare function canIUseGroupSetData(): boolean; +export declare function canIUseNextTick(): boolean; +export declare function canIUseCanvas2d(): boolean; +export declare function canIUseGetUserProfile(): boolean; +export {}; diff --git a/miniprogram_npm/@vant/weapp/common/version.js b/miniprogram_npm/@vant/weapp/common/version.js new file mode 100644 index 0000000..5937008 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/common/version.js @@ -0,0 +1,70 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.canIUseGetUserProfile = exports.canIUseCanvas2d = exports.canIUseNextTick = exports.canIUseGroupSetData = exports.canIUseAnimate = exports.canIUseFormFieldButton = exports.canIUseModel = exports.getSystemInfoSync = void 0; +var systemInfo; +function getSystemInfoSync() { + if (systemInfo == null) { + systemInfo = wx.getSystemInfoSync(); + } + return systemInfo; +} +exports.getSystemInfoSync = getSystemInfoSync; +function compareVersion(v1, v2) { + v1 = v1.split('.'); + v2 = v2.split('.'); + var len = Math.max(v1.length, v2.length); + while (v1.length < len) { + v1.push('0'); + } + while (v2.length < len) { + v2.push('0'); + } + for (var i = 0; i < len; i++) { + var num1 = parseInt(v1[i], 10); + var num2 = parseInt(v2[i], 10); + if (num1 > num2) { + return 1; + } + if (num1 < num2) { + return -1; + } + } + return 0; +} +function gte(version) { + var system = getSystemInfoSync(); + return compareVersion(system.SDKVersion, version) >= 0; +} +function canIUseModel() { + return gte('2.9.3'); +} +exports.canIUseModel = canIUseModel; +function canIUseFormFieldButton() { + return gte('2.10.3'); +} +exports.canIUseFormFieldButton = canIUseFormFieldButton; +function canIUseAnimate() { + return gte('2.9.0'); +} +exports.canIUseAnimate = canIUseAnimate; +function canIUseGroupSetData() { + return gte('2.4.0'); +} +exports.canIUseGroupSetData = canIUseGroupSetData; +function canIUseNextTick() { + try { + return wx.canIUse('nextTick'); + } + catch (e) { + return gte('2.7.1'); + } +} +exports.canIUseNextTick = canIUseNextTick; +function canIUseCanvas2d() { + return gte('2.9.0'); +} +exports.canIUseCanvas2d = canIUseCanvas2d; +function canIUseGetUserProfile() { + return !!wx.getUserProfile; +} +exports.canIUseGetUserProfile = canIUseGetUserProfile; diff --git a/miniprogram_npm/@vant/weapp/definitions/index.d.ts b/miniprogram_npm/@vant/weapp/definitions/index.d.ts new file mode 100644 index 0000000..c90321f --- /dev/null +++ b/miniprogram_npm/@vant/weapp/definitions/index.d.ts @@ -0,0 +1,29 @@ +/// +interface VantComponentInstance { + parent: WechatMiniprogram.Component.TrivialInstance; + children: WechatMiniprogram.Component.TrivialInstance[]; + index: number; + $emit: (name: string, detail?: unknown, options?: WechatMiniprogram.Component.TriggerEventOption) => void; + setView: (value: Record, callback?: () => void) => void; +} +export type VantComponentOptions = { + data?: Data; + field?: boolean; + classes?: string[]; + mixins?: string[]; + props?: Props; + relation?: { + relations: Record; + mixin: string; + }; + watch?: Record any>; + methods?: Methods; + beforeCreate?: () => void; + created?: () => void; + mounted?: () => void; + destroyed?: () => void; +} & ThisType, Props, Methods> & Record>; +export {}; diff --git a/miniprogram_npm/@vant/weapp/definitions/index.js b/miniprogram_npm/@vant/weapp/definitions/index.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/definitions/index.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/miniprogram_npm/@vant/weapp/dialog/dialog.d.ts b/miniprogram_npm/@vant/weapp/dialog/dialog.d.ts new file mode 100644 index 0000000..db2da5f --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/dialog.d.ts @@ -0,0 +1,55 @@ +/// +/// +export type Action = 'confirm' | 'cancel' | 'overlay'; +type DialogContext = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance; +interface DialogOptions { + lang?: string; + show?: boolean; + title?: string; + width?: string | number | null; + zIndex?: number; + theme?: string; + context?: (() => DialogContext) | DialogContext; + message?: string; + overlay?: boolean; + selector?: string; + ariaLabel?: string; + /** + * @deprecated use custom-class instead + */ + className?: string; + customStyle?: string; + transition?: string; + /** + * @deprecated use beforeClose instead + */ + asyncClose?: boolean; + beforeClose?: null | ((action: Action) => Promise | void); + businessId?: number; + sessionFrom?: string; + overlayStyle?: string; + appParameter?: string; + messageAlign?: string; + sendMessageImg?: string; + showMessageCard?: boolean; + sendMessagePath?: string; + sendMessageTitle?: string; + confirmButtonText?: string; + cancelButtonText?: string; + showConfirmButton?: boolean; + showCancelButton?: boolean; + closeOnClickOverlay?: boolean; + confirmButtonOpenType?: string; +} +declare const Dialog: { + (options: DialogOptions): Promise; + alert(options: DialogOptions): Promise; + confirm(options: DialogOptions): Promise; + close(): void; + stopLoading(): void; + currentOptions: DialogOptions; + defaultOptions: DialogOptions; + setDefaultOptions(options: DialogOptions): void; + resetDefaultOptions(): void; +}; +export default Dialog; diff --git a/miniprogram_npm/@vant/weapp/dialog/dialog.js b/miniprogram_npm/@vant/weapp/dialog/dialog.js new file mode 100644 index 0000000..400f4f1 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/dialog.js @@ -0,0 +1,92 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var queue = []; +var defaultOptions = { + show: false, + title: '', + width: null, + theme: 'default', + message: '', + zIndex: 100, + overlay: true, + selector: '#van-dialog', + className: '', + asyncClose: false, + beforeClose: null, + transition: 'scale', + customStyle: '', + messageAlign: '', + overlayStyle: '', + confirmButtonText: '确认', + cancelButtonText: '取消', + showConfirmButton: true, + showCancelButton: false, + closeOnClickOverlay: false, + confirmButtonOpenType: '', +}; +var currentOptions = __assign({}, defaultOptions); +function getContext() { + var pages = getCurrentPages(); + return pages[pages.length - 1]; +} +var Dialog = function (options) { + options = __assign(__assign({}, currentOptions), options); + return new Promise(function (resolve, reject) { + var context = (typeof options.context === 'function' + ? options.context() + : options.context) || getContext(); + var dialog = context.selectComponent(options.selector); + delete options.context; + delete options.selector; + if (dialog) { + dialog.setData(__assign({ callback: function (action, instance) { + action === 'confirm' ? resolve(instance) : reject(instance); + } }, options)); + wx.nextTick(function () { + dialog.setData({ show: true }); + }); + queue.push(dialog); + } + else { + console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确'); + } + }); +}; +Dialog.alert = function (options) { return Dialog(options); }; +Dialog.confirm = function (options) { + return Dialog(__assign({ showCancelButton: true }, options)); +}; +Dialog.close = function () { + queue.forEach(function (dialog) { + dialog.close(); + }); + queue = []; +}; +Dialog.stopLoading = function () { + queue.forEach(function (dialog) { + dialog.stopLoading(); + }); +}; +Dialog.currentOptions = currentOptions; +Dialog.defaultOptions = defaultOptions; +Dialog.setDefaultOptions = function (options) { + currentOptions = __assign(__assign({}, currentOptions), options); + Dialog.currentOptions = currentOptions; +}; +Dialog.resetDefaultOptions = function () { + currentOptions = __assign({}, defaultOptions); + Dialog.currentOptions = currentOptions; +}; +Dialog.resetDefaultOptions(); +exports.default = Dialog; diff --git a/miniprogram_npm/@vant/weapp/dialog/index.d.ts b/miniprogram_npm/@vant/weapp/dialog/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/dialog/index.js b/miniprogram_npm/@vant/weapp/dialog/index.js new file mode 100644 index 0000000..b0acfa0 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/index.js @@ -0,0 +1,135 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var button_1 = require("../mixins/button"); +var color_1 = require("../common/color"); +var utils_1 = require("../common/utils"); +(0, component_1.VantComponent)({ + mixins: [button_1.button], + classes: ['cancle-button-class', 'confirm-button-class'], + props: { + show: { + type: Boolean, + observer: function (show) { + !show && this.stopLoading(); + }, + }, + title: String, + message: String, + theme: { + type: String, + value: 'default', + }, + confirmButtonId: String, + className: String, + customStyle: String, + asyncClose: Boolean, + messageAlign: String, + beforeClose: null, + overlayStyle: String, + useSlot: Boolean, + useTitleSlot: Boolean, + useConfirmButtonSlot: Boolean, + useCancelButtonSlot: Boolean, + showCancelButton: Boolean, + closeOnClickOverlay: Boolean, + confirmButtonOpenType: String, + width: null, + zIndex: { + type: Number, + value: 2000, + }, + confirmButtonText: { + type: String, + value: '确认', + }, + cancelButtonText: { + type: String, + value: '取消', + }, + confirmButtonColor: { + type: String, + value: color_1.RED, + }, + cancelButtonColor: { + type: String, + value: color_1.GRAY, + }, + showConfirmButton: { + type: Boolean, + value: true, + }, + overlay: { + type: Boolean, + value: true, + }, + transition: { + type: String, + value: 'scale', + }, + rootPortal: { + type: Boolean, + value: false, + }, + }, + data: { + loading: { + confirm: false, + cancel: false, + }, + callback: (function () { }), + }, + methods: { + onConfirm: function () { + this.handleAction('confirm'); + }, + onCancel: function () { + this.handleAction('cancel'); + }, + onClickOverlay: function () { + this.close('overlay'); + }, + close: function (action) { + var _this = this; + this.setData({ show: false }); + wx.nextTick(function () { + _this.$emit('close', action); + var callback = _this.data.callback; + if (callback) { + callback(action, _this); + } + }); + }, + stopLoading: function () { + this.setData({ + loading: { + confirm: false, + cancel: false, + }, + }); + }, + handleAction: function (action) { + var _a; + var _this = this; + this.$emit(action, { dialog: this }); + var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose; + if (!asyncClose && !beforeClose) { + this.close(action); + return; + } + this.setData((_a = {}, + _a["loading.".concat(action)] = true, + _a)); + if (beforeClose) { + (0, utils_1.toPromise)(beforeClose(action)).then(function (value) { + if (value) { + _this.close(action); + } + else { + _this.stopLoading(); + } + }); + } + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/dialog/index.json b/miniprogram_npm/@vant/weapp/dialog/index.json new file mode 100644 index 0000000..43417fc --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/index.json @@ -0,0 +1,9 @@ +{ + "component": true, + "usingComponents": { + "van-popup": "../popup/index", + "van-button": "../button/index", + "van-goods-action": "../goods-action/index", + "van-goods-action-button": "../goods-action-button/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/dialog/index.wxml b/miniprogram_npm/@vant/weapp/dialog/index.wxml new file mode 100644 index 0000000..a1d8e3c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/index.wxml @@ -0,0 +1,125 @@ + + + + + + {{ title }} + + + + + {{ message }} + + + + + {{ cancelButtonText }} + + + {{ confirmButtonText }} + + + + + + + + + {{ cancelButtonText }} + + + + + + + + {{ confirmButtonText }} + + + + diff --git a/miniprogram_npm/@vant/weapp/dialog/index.wxss b/miniprogram_npm/@vant/weapp/dialog/index.wxss new file mode 100644 index 0000000..507a789 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/dialog/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-dialog{background-color:var(--dialog-background-color,#fff);border-radius:var(--dialog-border-radius,16px);font-size:var(--dialog-font-size,16px);overflow:hidden;top:45%!important;width:var(--dialog-width,320px)}@media (max-width:321px){.van-dialog{width:var(--dialog-small-screen-width,90%)}}.van-dialog__header{font-weight:var(--dialog-header-font-weight,500);line-height:var(--dialog-header-line-height,24px);padding-top:var(--dialog-header-padding-top,24px);text-align:center}.van-dialog__header--isolated{padding:var(--dialog-header-isolated-padding,24px 0)}.van-dialog__message{-webkit-overflow-scrolling:touch;font-size:var(--dialog-message-font-size,14px);line-height:var(--dialog-message-line-height,20px);max-height:var(--dialog-message-max-height,60vh);overflow-y:auto;padding:var(--dialog-message-padding,24px);text-align:center}.van-dialog__message-text{word-wrap:break-word}.van-dialog__message--hasTitle{color:var(--dialog-has-title-message-text-color,#646566);padding-top:var(--dialog-has-title-message-padding-top,8px)}.van-dialog__message--round-button{color:#323233;padding-bottom:16px}.van-dialog__message--left{text-align:left}.van-dialog__message--right{text-align:right}.van-dialog__message--justify{text-align:justify}.van-dialog__footer{display:flex}.van-dialog__footer--round-button{padding:8px 24px 16px!important;position:relative!important}.van-dialog__button{flex:1}.van-dialog__cancel,.van-dialog__confirm{border:0!important}.van-dialog-bounce-enter{opacity:0;transform:translate3d(-50%,-50%,0) scale(.7)}.van-dialog-bounce-leave-active{opacity:0;transform:translate3d(-50%,-50%,0) scale(.9)} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/empty/index.d.ts b/miniprogram_npm/@vant/weapp/empty/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/empty/index.js b/miniprogram_npm/@vant/weapp/empty/index.js new file mode 100644 index 0000000..755e638 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +(0, component_1.VantComponent)({ + props: { + description: String, + image: { + type: String, + value: 'default', + }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/empty/index.json b/miniprogram_npm/@vant/weapp/empty/index.json new file mode 100644 index 0000000..a89ef4d --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} diff --git a/miniprogram_npm/@vant/weapp/empty/index.wxml b/miniprogram_npm/@vant/weapp/empty/index.wxml new file mode 100644 index 0000000..9c7b719 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.wxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + {{ description }} + + + + + + diff --git a/miniprogram_npm/@vant/weapp/empty/index.wxs b/miniprogram_npm/@vant/weapp/empty/index.wxs new file mode 100644 index 0000000..cf92ece --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.wxs @@ -0,0 +1,15 @@ +/* eslint-disable */ +var PRESETS = ['error', 'search', 'default', 'network']; + +function imageUrl(image) { + if (PRESETS.indexOf(image) !== -1) { + return 'https://img.yzcdn.cn/vant/empty-image-' + image + '.png'; + } + + return image; +} + +module.exports = { + imageUrl: imageUrl, +}; + diff --git a/miniprogram_npm/@vant/weapp/empty/index.wxss b/miniprogram_npm/@vant/weapp/empty/index.wxss new file mode 100644 index 0000000..0fb74fe --- /dev/null +++ b/miniprogram_npm/@vant/weapp/empty/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-empty{align-items:center;box-sizing:border-box;display:flex;flex-direction:column;justify-content:center;padding:32px 0}.van-empty__image{height:160px;width:160px}.van-empty__image:empty{display:none}.van-empty__image__img{height:100%;width:100%}.van-empty__image:not(:empty)+.van-empty__image{display:none}.van-empty__description{color:#969799;font-size:14px;line-height:20px;margin-top:16px;padding:0 60px}.van-empty__description:empty,.van-empty__description:not(:empty)+.van-empty__description{display:none}.van-empty__bottom{margin-top:24px} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/field/index.d.ts b/miniprogram_npm/@vant/weapp/field/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/miniprogram_npm/@vant/weapp/field/index.js b/miniprogram_npm/@vant/weapp/field/index.js new file mode 100644 index 0000000..ee64d5f --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.js @@ -0,0 +1,152 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var utils_1 = require("../common/utils"); +var component_1 = require("../common/component"); +var props_1 = require("./props"); +(0, component_1.VantComponent)({ + field: true, + classes: ['input-class', 'right-icon-class', 'label-class'], + props: __assign(__assign(__assign(__assign({}, props_1.commonProps), props_1.inputProps), props_1.textareaProps), { size: String, icon: String, label: String, error: Boolean, center: Boolean, isLink: Boolean, leftIcon: String, rightIcon: String, autosize: null, required: Boolean, iconClass: String, clickable: Boolean, inputAlign: String, customStyle: String, errorMessage: String, arrowDirection: String, showWordLimit: Boolean, errorMessageAlign: String, readonly: { + type: Boolean, + observer: 'setShowClear', + }, clearable: { + type: Boolean, + observer: 'setShowClear', + }, clearTrigger: { + type: String, + value: 'focus', + }, border: { + type: Boolean, + value: true, + }, titleWidth: { + type: String, + value: '6.2em', + }, clearIcon: { + type: String, + value: 'clear', + }, extraEventParams: { + type: Boolean, + value: false, + } }), + data: { + focused: false, + innerValue: '', + showClear: false, + }, + watch: { + value: function (value) { + if (value !== this.value) { + this.setData({ innerValue: value }); + this.value = value; + this.setShowClear(); + } + }, + clearTrigger: function () { + this.setShowClear(); + }, + }, + created: function () { + this.value = this.data.value; + this.setData({ innerValue: this.value }); + }, + methods: { + formatValue: function (value) { + var maxlength = this.data.maxlength; + if (maxlength !== -1 && value.length > maxlength) { + return value.slice(0, maxlength); + } + return value; + }, + onInput: function (event) { + var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a; + var formatValue = this.formatValue(value); + this.value = formatValue; + this.setShowClear(); + return this.emitChange(__assign(__assign({}, event.detail), { value: formatValue })); + }, + onFocus: function (event) { + this.focused = true; + this.setShowClear(); + this.$emit('focus', event.detail); + }, + onBlur: function (event) { + this.focused = false; + this.setShowClear(); + this.$emit('blur', event.detail); + }, + onClickIcon: function () { + this.$emit('click-icon'); + }, + onClickInput: function (event) { + this.$emit('click-input', event.detail); + }, + onClear: function () { + var _this = this; + this.setData({ innerValue: '' }); + this.value = ''; + this.setShowClear(); + (0, utils_1.nextTick)(function () { + _this.emitChange({ value: '' }); + _this.$emit('clear', ''); + }); + }, + onConfirm: function (event) { + var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a; + this.value = value; + this.setShowClear(); + this.$emit('confirm', value); + }, + setValue: function (value) { + this.value = value; + this.setShowClear(); + if (value === '') { + this.setData({ innerValue: '' }); + } + this.emitChange({ value: value }); + }, + onLineChange: function (event) { + this.$emit('linechange', event.detail); + }, + onKeyboardHeightChange: function (event) { + this.$emit('keyboardheightchange', event.detail); + }, + onBindNicknameReview: function (event) { + this.$emit('nicknamereview', event.detail); + }, + emitChange: function (detail) { + var extraEventParams = this.data.extraEventParams; + this.setData({ value: detail.value }); + var result; + var data = extraEventParams + ? __assign(__assign({}, detail), { callback: function (data) { + result = data; + } }) : detail.value; + this.$emit('input', data); + this.$emit('change', data); + return result; + }, + setShowClear: function () { + var _a = this.data, clearable = _a.clearable, readonly = _a.readonly, clearTrigger = _a.clearTrigger; + var _b = this, focused = _b.focused, value = _b.value; + var showClear = false; + if (clearable && !readonly) { + var hasValue = !!value; + var trigger = clearTrigger === 'always' || (clearTrigger === 'focus' && focused); + showClear = hasValue && trigger; + } + this.setView({ showClear: showClear }); + }, + noop: function () { }, + }, +}); diff --git a/miniprogram_npm/@vant/weapp/field/index.json b/miniprogram_npm/@vant/weapp/field/index.json new file mode 100644 index 0000000..5906c50 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../cell/index", + "van-icon": "../icon/index" + } +} diff --git a/miniprogram_npm/@vant/weapp/field/index.wxml b/miniprogram_npm/@vant/weapp/field/index.wxml new file mode 100644 index 0000000..6018993 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.wxml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/miniprogram_npm/@vant/weapp/field/index.wxs b/miniprogram_npm/@vant/weapp/field/index.wxs new file mode 100644 index 0000000..78575b9 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.wxs @@ -0,0 +1,18 @@ +/* eslint-disable */ +var style = require('../wxs/style.wxs'); +var addUnit = require('../wxs/add-unit.wxs'); + +function inputStyle(autosize) { + if (autosize && autosize.constructor === 'Object') { + return style({ + 'min-height': addUnit(autosize.minHeight), + 'max-height': addUnit(autosize.maxHeight), + }); + } + + return ''; +} + +module.exports = { + inputStyle: inputStyle, +}; diff --git a/miniprogram_npm/@vant/weapp/field/index.wxss b/miniprogram_npm/@vant/weapp/field/index.wxss new file mode 100644 index 0000000..5f7d306 --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-field{--cell-icon-size:var(--field-icon-size,16px)}.van-field__label{color:var(--field-label-color,#646566)}.van-field__label--disabled{color:var(--field-disabled-text-color,#c8c9cc)}.van-field__body{align-items:center;display:flex}.van-field__body--textarea{box-sizing:border-box;line-height:1.2em;min-height:var(--cell-line-height,24px);padding:3.6px 0}.van-field__control:empty+.van-field__control{display:block}.van-field__control{background-color:initial;border:0;box-sizing:border-box;color:var(--field-input-text-color,#323233);display:none;height:var(--cell-line-height,24px);line-height:inherit;margin:0;min-height:var(--cell-line-height,24px);padding:0;position:relative;resize:none;text-align:left;width:100%}.van-field__control:empty{display:none}.van-field__control--textarea{height:var(--field-text-area-min-height,18px);min-height:var(--field-text-area-min-height,18px)}.van-field__control--error{color:var(--field-input-error-text-color,#ee0a24)}.van-field__control--disabled{background-color:initial;color:var(--field-input-disabled-text-color,#c8c9cc);opacity:1}.van-field__control--center{text-align:center}.van-field__control--right{text-align:right}.van-field__control--custom{align-items:center;display:flex;min-height:var(--cell-line-height,24px)}.van-field__placeholder{color:var(--field-placeholder-text-color,#c8c9cc);left:0;pointer-events:none;position:absolute;right:0;top:0}.van-field__placeholder--error{color:var(--field-error-message-color,#ee0a24)}.van-field__icon-root{align-items:center;display:flex;min-height:var(--cell-line-height,24px)}.van-field__clear-root,.van-field__icon-container{line-height:inherit;margin-right:calc(var(--padding-xs, 8px)*-1);padding:0 var(--padding-xs,8px);vertical-align:middle}.van-field__button,.van-field__clear-root,.van-field__icon-container{flex-shrink:0}.van-field__clear-root{color:var(--field-clear-icon-color,#c8c9cc);font-size:var(--field-clear-icon-size,16px)}.van-field__icon-container{color:var(--field-icon-container-color,#969799);font-size:var(--field-icon-size,16px)}.van-field__icon-container:empty{display:none}.van-field__button{padding-left:var(--padding-xs,8px)}.van-field__button:empty{display:none}.van-field__error-message{color:var(--field-error-message-color,#ee0a24);display:block;font-size:var(--field-error-message-text-font-size,12px);text-align:left}.van-field__error-message--center{text-align:center}.van-field__error-message--right{text-align:right}.van-field__word-limit{color:var(--field-word-limit-color,#646566);font-size:var(--field-word-limit-font-size,12px);line-height:var(--field-word-limit-line-height,16px);margin-top:var(--padding-base,4px);text-align:right}.van-field__word-num{display:inline}.van-field__word-num--full{color:var(--field-word-num-full-color,#ee0a24)} \ No newline at end of file diff --git a/miniprogram_npm/@vant/weapp/field/input.wxml b/miniprogram_npm/@vant/weapp/field/input.wxml new file mode 100644 index 0000000..86b288b --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/input.wxml @@ -0,0 +1,31 @@ + + diff --git a/miniprogram_npm/@vant/weapp/field/props.d.ts b/miniprogram_npm/@vant/weapp/field/props.d.ts new file mode 100644 index 0000000..5cd130a --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/props.d.ts @@ -0,0 +1,4 @@ +/// +export declare const commonProps: WechatMiniprogram.Component.PropertyOption; +export declare const inputProps: WechatMiniprogram.Component.PropertyOption; +export declare const textareaProps: WechatMiniprogram.Component.PropertyOption; diff --git a/miniprogram_npm/@vant/weapp/field/props.js b/miniprogram_npm/@vant/weapp/field/props.js new file mode 100644 index 0000000..5ec647b --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/props.js @@ -0,0 +1,59 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.textareaProps = exports.inputProps = exports.commonProps = void 0; +exports.commonProps = { + value: String, + placeholder: String, + placeholderStyle: String, + placeholderClass: String, + disabled: Boolean, + maxlength: { + type: Number, + value: -1, + }, + cursorSpacing: { + type: Number, + value: 50, + }, + autoFocus: Boolean, + focus: Boolean, + cursor: { + type: Number, + value: -1, + }, + selectionStart: { + type: Number, + value: -1, + }, + selectionEnd: { + type: Number, + value: -1, + }, + adjustPosition: { + type: Boolean, + value: true, + }, + holdKeyboard: Boolean, +}; +exports.inputProps = { + type: { + type: String, + value: 'text', + }, + password: Boolean, + confirmType: String, + confirmHold: Boolean, + alwaysEmbed: Boolean, +}; +exports.textareaProps = { + autoHeight: Boolean, + fixed: Boolean, + showConfirmBar: { + type: Boolean, + value: true, + }, + disableDefaultPadding: { + type: Boolean, + value: true, + }, +}; diff --git a/miniprogram_npm/@vant/weapp/field/textarea.wxml b/miniprogram_npm/@vant/weapp/field/textarea.wxml new file mode 100644 index 0000000..945d03e --- /dev/null +++ b/miniprogram_npm/@vant/weapp/field/textarea.wxml @@ -0,0 +1,32 @@ + + +